Twitter api 1.1 update_with_media [英] Twitter api 1.1 update_with_media

查看:30
本文介绍了Twitter api 1.1 update_with_media的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更改我的 php 代码以与新 API 兼容,但我坚持使用 update_with_media.这是我的代码:

i'm changing my php code to be compatible with new API and i'm stuck with update_with_media. This is my code:

$image = constant('PATH_UPLOAD').$db_data['post_image'];
$connection = new TwitterOAuth(constant('CONSUMER_KEY'), constant('CONSUMER_SECRET'), $db_data['tw_oauth_token'], $db_data['tw_oauth_secret']);          
$content = $connection->OAuthRequest('https://api.twitter.com/1.1/account/verify_credentials.json', 'GET', array());
$twitterInfo = json_decode($content);                      
$resp_tw = $connection->OAuthRequest('https://api.twitter.com/1.1/statuses/update_with_media.json', 'POST', 
             array(
               'status'   => html_entity_decode($db_data['post_text'],ENT_QUOTES,'UTF-8'),              
                 'media[]'  => "@{$image}"
             )         
           );                          

然后它返回

{"errors":[{"code":189,"message":"Error creating status"}]}

可能是什么问题/我做错了什么?

What might be the problem / what i'm doing wrong?

推荐答案

你可以这样试试:

$tmhOAuth = new tmhOAuth(array(
  'consumer_key' => 'abc',
  'consumer_secret' => 'abc',
  'user_token' => 'abc',
  'user_secret' => 'abc',
));

$response = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update_with_media'),
array(
       'status' => $message,
       'media[]'  => file_get_contents($image)
));
if ($response != 200) {
    //Do something if the request was unsuccessful
}

有我的代码测试 https://twitter.com/wallapps/status/357137553691906048

这篇关于Twitter api 1.1 update_with_media的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆