【问题标题】:does abraham's twitteroauth library work for update_with_media?abraham 的 twitteroauth 库是否适用于 update_with_media?
【发布时间】:2013-10-30 17:59:35
【问题描述】:

abraham 的 twitteroauth 库是否适用于 update_with_media?

我正在使用下面的代码,但它返回给我 stdClass 对象 ( [请求] => /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/作为网址

【问题讨论】:

  • 据我所知,您不需要 ;type=image/jpeg;filename={$image} 如果您不使用它们,它会起作用吗?
  • 不....没有它就不行
  • 对于新的 Twitter 媒体上传检查这个解决方案:stackoverflow.com/questions/26340704/…

标签: php twitter twitter-oauth


【解决方案1】:

是的!更改两个文件 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);

【讨论】:

  • 从 api 1.1 开始,您必须在 twitterOAuth.php 中更改建议的“上传”方法。只需删除 $this->host 的 2 个定义(github diff 上的第 168 和 170 行)。为我工作,谢谢!
【解决方案2】:

根据图书馆作者在其他地方的回答 - 不,它还不适用于 update_with_media。

TwitterOAuth 目前不支持媒体上传。希望补充 未来的支持。 5 月 10 日,@abraham 在update_with_media using abraham's twitteroauth

【讨论】:

    【解决方案3】:
     $params = array('media[]' => file_get_contents($image_url), 'status' => $messafe);
     $twit = $connection->upload('statuses/update_with_media',$params);
    

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

    【讨论】:

      猜你喜欢
      • 2012-05-18
      • 2015-09-25
      • 1970-01-01
      • 2015-06-17
      • 1970-01-01
      • 1970-01-01
      • 2015-11-16
      • 2015-07-11
      • 1970-01-01
      相关资源
      最近更新 更多