我的代码更改了Twitter状态,遗憾的是它没有发布图片。
请查看我的代码并帮我发布带文字的图片。
$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";
答案 0 :(得分:5)
似乎您应首先上传媒体(创建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
答案 1 :(得分:2)
$connection = new TwitterOAuth($consumerkey, $consumersecret, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");
首先检查连接
$result = $connection->upload('media/upload', array('media' => 'Relative Path to your media'));
$mediaID = $result->media_id;
$parameters = array('status' => 'First tweet','media_ids' => $mediaID);
$response = $connection->post('statuses/update', $parameters);
以上代码在我的实例中起作用