我有代码更改推特状态,不幸的是它没有发布图片.
$consumerKey = ''; $consumerSecret = ''; $oAuthToken = ''; $oAuthSecret = ''; include "OAuth.PHP"; include "twitteroauth.PHP"; require_once('twitteroauth.PHP'); $tweet = new TwitterOAuth($consumerKey,$consumerSecret,$oAuthToken,$oAuthSecret); $tweet->post('statuses/update',array('status' => 'PHP --> example.co.uk <-- ','media[]' => "http://www.balanced-hr.com/wp- content/uploads/2014/08/majster.jpg")); echo "your message has been sent to twitter API";
解决方法
似乎您应该首先上传您的媒体(创建TwitterOAuth对象后)
$media = $tweet->upload('media/upload',array('media' => 'path_to_your_file'));
然后设置推文的参数(如状态和媒体)
$parameters = array( 'status' => 'Your Tweet status','media_ids' => $media->media_id_string);
您可以在同一条推文中查看文档以上传最多4个媒体资源
然后发送带有参数的推文.
$send_tweet = $connection->post('statuses/update',$parameters);
您可以在此处查看使用媒体的示例:https://twitteroauth.com/
这里的状态/更新参考:https://dev.twitter.com/rest/reference/post/statuses/update