2

abraham 的 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');

有人知道如何解决这个问题吗?

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

4

3 回答 3

5

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

 $params = array('media[]' => '@'.$image_url, 'status' => $messafe);
 $twit = $connection->upload('statuses/update_with_media',$params);
于 2013-05-02T13:50:14.427 回答
2

根据图书馆作者在其他地方的回答 - 不,它还不能与 update_with_media 一起使用。

TwitterOAuth 目前不支持媒体上传。我希望在未来增加支持。5 月 10 日 @abraham 在 update_with_media使用 abraham 的 twitteroauth

于 2012-07-03T12:45:43.410 回答
0
 $params = array('media[]' => file_get_contents($image_url), 'status' => $messafe);
 $twit = $connection->upload('statuses/update_with_media',$params);

如果 update_with_media 不起作用,请稍作改动

于 2013-10-30T09:59:35.033 回答