dqssst0144 2014-06-15 17:29
浏览 105
已采纳

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

Here is var_dump($tmhOAuth->response); I am not able to upload.

Php error :

Notice: Undefined index: Temp_Token ...

Undefined index: Temp_Secret

Notice: Undefined index: Img_Url ...

Undefined offset: 1 in C:\wamp1\www\download\twt\tmhOAuth.php on line 218

Undefined index: oauth_token in C:\wamp1\www\download\twt\callback.php on line 30

Notice: Undefined index: oauth_token_secret in C:\wamp1\www\download\twt\callback.php on line 31

Notice: Use of undefined constant tmhUtilities - assumed 'tmhUtilities' in C:\wamp1\www\download\twt\callback.php on line 54

I have the code from: http://www.stirring-interactive.com/blog/tweet-images-using-twitter-api/.

Is a problem with the cookie? I have no idea where is the problem. I try from a few days to post media on twitter using api but with no success.

<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

This is my php code 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条回答 默认 最新

  • dpl22899 2014-11-21 15:56
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题