亚伯拉罕的twitteroauth图书馆是否适用于update_with_media?

Muj*_*der 2 php twitter twitter-oauth

亚伯拉罕的twitteroauth图书馆是否适用于update_with_media?

我正在使用下面的代码,但它返回stdClass对象([request] => /1/statuses/update_with_media.json [error] =>创建状态时出错.)

session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');


if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
  header('Location: ./clearsessions.php');
}

 $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['access_token']['oauth_token'], $_SESSION['access_token']['oauth_token_secret']);

$image = './images/5298.png';
$content = $connection->post('statuses/update_with_media', 
  array(
   'media[]' => '@{$image};type=image/jpeg;filename={$image}', 
   'status' => 'My current location'));

include('html.inc');
Run Code Online (Sandbox Code Playgroud)

任何人都知道如何解决这个问题?

编辑1:我使用https://upload.twitter.com/1/作为网址

小智 5

是的,它确实!更改两个文件Oauth.php和twitteroauth.php,如此链接https://github.com/robhaswell/twitteroauth/commit/7f5bfd2450cb1cff71641d7ea55e118f5a42885d所述,并使用这样的$ connection-> upload方法.

 $params = array('media[]' => '@'.$image_url, 'status' => $messafe);
 $twit = $connection->upload('statuses/update_with_media',$params);
Run Code Online (Sandbox Code Playgroud)

  • 从api 1.1开始,您必须在twitterOAuth.php中更改建议的"上传"方法.Juste删除$ this-> host的2个定义(github diff上的第168行和第170行).为我工作,谢谢! (2认同)