我有以下的工作代码,代码只是发布状态和图像om我的推特页面。发布状态+图片上有推特TwitterAPIExchange
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "xxx",
'oauth_access_token_secret' => "xxx",
'consumer_key' => "xxx",
'consumer_secret' => "xxx"
);
$url = "https://api.twitter.com/1.1/statuses/update_with_media.json";
$requestMethod = "POST";
$tweetmsg = $_POST['post_text'];
$twimage = "Images/twitter-icon.png";
$postfields = array(
'status' => $tweetmsg,
'media[]' => "@{$twimage}"
);
try {
$twitter = new TwitterAPIExchange($settings);
$twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
echo "Success, you just tweeted!";
} catch (Exception $ex) {
echo $ex->getMessage();
}
}
该图像现在被放置在我的项目中的文件夹(图像)。我希望用户能够从他自己的计算机中选择一张图片,写入一个描述,然后发送它。我有以下简单的HTML表单发布:
<form method="post" action="index.php">
<textarea id="post_text" name="post_text" type="text"></textarea>
<input type="file" name="post_file" id="post_file" multiple accept="image/*" value="Choose a file"/>
<button type="submit" id="btn_submit">Submit</button>
</from>
那么,你们有任何提示或指南,可以帮助我解决我的问题?我是以正确的方式思考,还是应该以另一种方式解决问题?谢谢!
而且您的网址,HTTPS://api.twitter.com/1.1/statuses/ update_with_media.json,是错误的。它应该是:https://upload.twitter.com/1.1/statuses/update_with_media.json –
感谢您的提示,我会尝试一下! – user2190027