我无法使用API​​在Twitter上传媒体

时间:2014-06-15 17:29:56

标签: php api twitter media twitter-oauth

这是var_dump($ tmhOAuth-> response); 我无法上传。

Php错误:

注意:未定义的索引:Temp_Token ...

未定义的索引:Temp_Secret

注意:未定义的索引:Img_Url ...

未定义的偏移量:第218行的C:\ wamp1 \ www \ download \ twt \ tmhOAuth.php中的1

未定义的索引:第30行的C:\ wamp1 \ www \ download \ twt \ callback.php中的oauth_token

注意:未定义的索引:第31行的C:\ wamp1 \ www \ download \ twt \ callback.php中的oauth_token_secret

注意:使用未定义的常量tmhUtilities - 假设' tmhUtilities'在第54行的C:\ wamp1 \ www \ download \ twt \ callback.php

我的代码来自:http://www.stirring-interactive.com/blog/tweet-images-using-twitter-api/

Cookie存在问题吗?我不知道问题出在哪里。我尝试用几天时间在Twitter上使用api发布媒体但没有成功。

<code>array (size=7)
'raw' => string '' (length=0)
'headers' => 
  array (size=22)
  'HTTP/1.1 401 Unauthorized' => string '' (length=0)
  'cache-control' => string 'no-cache, no-store, must-revalidate, pre-check=0, post-check=0' (length=62)
  'content-encoding' => string 'gzip' (length=4)
  'content-length' => string '41' (length=2)
  'content-type' => string 'text/html; charset=utf-8' (length=24)
  'date' => string 'Sun, 15 Jun 2014 16:48:05 GMT' (length=29)
  'expires' => string 'Tue, 31 Mar 1981 05:00:00 GMT' (length=29)
  'last-modified' => string 'Sun, 15 Jun 2014 16:48:05 GMT' (length=29)
  'pragma' => string 'no-cache' (length=8)
  'server' => string 'tfe' (length=3)
  'set-cookie' => 
    array (size=2)
      0 => string '_twitter_sess=BAh7BzoPY3JlYXRlZF9hdGwrCFa%252FbaBGAToHaWQiJTllNmNlMGUzMGJiYjJl%250AODJjNmE5NDIzN2Y4NTc1ZTI2--7841cbe45707fc68c30ba566c184d6e6344b7226; domain=.twitter.com; path=/; secure; HttpOnly' (length=196)
      1 => string 'guest_id=v1%3A140285088532045126; Domain=.twitter.com; Path=/; Expires=Tue, 14-Jun-2016 16:48:05 UTC' (length=100)
  'status' => string '401 Unauthorized' (length=16)
  'strict-transport-security' => string 'max-age=631138519' (length=17)
  'vary' => string 'Accept-Encoding' (length=15)
  'x-content-type-options' => string 'nosniff' (length=7)
  'x-frame-options' => string 'SAMEORIGIN' (length=10)
  'x-mid' => string 'b41b68c3d8a9b195e0aca9faf30067dd1d464be6' (length=40)
  'x-runtime' => string '0.00959' (length=7)
  'x-transaction' => string '55a9e48507f88490' (length=16)
  'x-ua-compatible' => string 'IE=edge,chrome=1' (length=16)
  'x-xss-protection' => string '1; mode=block' (length=13)
  '' => string '' (length=0)
  'code' => int 0
  'response' => boolean false
 'info' => 
   array (size=26)
  'url' => string 'https://api.twitter.com/1.1/statuses/update_with_media.json' (length=59)
  'content_type' => null
  'http_code' => int 0
  'header_size' => int 0
  'request_size' => int 0
  'filetime' => int -1
  'ssl_verify_result' => int 20
  'redirect_count' => int 0
  'total_time' => float 0.453
  'namelookup_time' => float 0
  'connect_time' => float 0.156
  'pretransfer_time' => float 0
  'size_upload' => float 0
  'size_download' => float 0
  'speed_download' => float 0
  'speed_upload' => float 0
  'download_content_length' => float -1
  'upload_content_length' => float -1
  'starttransfer_time' => float 0
  'redirect_time' => float 0
  'certinfo' => 
    array (size=0)
      empty
  'primary_ip' => string '199.16.156.104' (length=14)
  'primary_port' => int 443
  'local_ip' => string '192.168.0.103' (length=13)
  'local_port' => int 58021
  'redirect_url' => string '' (length=0)
'error' => string 'couldn't open file "./"' (length=23)
'errno' => int 26

这是我的php代码callback.php

<?php

require 'config.php';
require 'tmhOAuth.php';
require 'tmhUtilities.php';

/// retrive temp access token from cookie 
$token = $_COOKIE['Temp_Token'];
$secret = $_COOKIE['Temp_Secret'];
$img = $_COOKIE['Img_Url'];
$txt = $_COOKIE['Tweet_Txt'];


$tmhOAuth = new tmhOAuth(array(
 'consumer_key'    => API_KEY,
'consumer_secret' => API_SEC,
'user_token'      => $token,
'user_secret'     => $secret,   
'curl_ssl_verifypeer'   => false
));

/// Ask Twitter for correct access token 

$tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array(  
    // pass the oauth_verifier received from Twitter  
    'oauth_verifier'    => $_GET["oauth_verifier"]  
)); 

$response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
$tmhOAuth->config["user_token"] = $response['oauth_token'];  
$tmhOAuth->config["user_secret"] = $response['oauth_token_secret']; 


$img = './'.$img;

$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]'  => "@{$img}",
'status'   => "$txt" // Don't give up..
),
true, // use auth
true  // multipart
);


var_dump($tmhOAuth->response);

if ($code == 200){
  // tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
  echo '<h1>Your image tweet has been sent successfully</h1>';
}else{
  // display the error 
  tmhUtilities::pr($tmhOAuth->response['response']);
  return tmhUtilities;
}





?>
<php>

1 个答案:

答案 0 :(得分:0)