gpt4 book ai didi

PHP - 将媒体/图片发布到推特

转载 作者:可可西里 更新时间:2023-11-01 00:20:02 25 4
gpt4 key购买 nike

我得到了更改 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";

最佳答案

似乎你应该先上传你的媒体(在创建 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

关于PHP - 将媒体/图片发布到推特,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29897694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com