我有以下的工作代碼,代碼只是發佈狀態和圖像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