【发布时间】:2018-03-02 00:30:04
【问题描述】:
我有以下工作代码,该代码只是在我的 Twitter 页面上发布状态和图像。
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>
那么你们有什么可以帮助我解决问题的提示或指南吗?我是否以正确的方式思考,或者我应该以另一种方式解决问题?谢谢!
【问题讨论】: