如何在twitter中使用php共享圖像?我知道它使用Twitter的圖片上傳api。但我不知道如何實現這一點?請幫忙找到解決辦法。提前感謝。Twitter圖像共享
0
A
回答
0
https://dev.twitter.com/docs/api/1/post/statuses/update_with_media
上面的鏈接了所有我認爲必要的信息。
3
以下是關於twitter圖片共享的文檔。
https://dev.twitter.com/docs/api/1/post/statuses/update_with_media
下面是支持Twitter圖片上傳唯一的PHP庫。
https://github.com/themattharris/tmhOAuth
和這裏的圖像共享工作的例子。一對夫婦編輯你的套餐。
<?php
if ($_POST['message'] && $_FILES['image']['tmp_name'])
{
require 'tmhOAuth.php';
list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']);
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => OAUTH_CONSUMER_KEY,
'consumer_secret' => OAUTH_CONSUMER_SECRET,
'user_token' => $oauth_token,
'user_secret' => $oauth_token_secret,
));
$image = "{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}";
$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
array(
'media[]' => "@{$image}",
'status' => " " . $status //A space is needed because twitter b0rks if first char is an @
),
true, // use auth
true // multipart
);
if ($code == 200) {
$json = json_decode($tmhOAuth->response['response']);
if ($_SERVER['HTTPS'] == "on") {
$image_url = $json->entities->media[0]->media_url_https;
}
else {
$image_url = $json->entities->media[0]->media_url;
}
$text = $json->text;
$content = "<p>Upload success. Image posted to Twitter.</p>
<p><img src=\"" . IMAGE_PROXY_URL . "x50/" . $image_url . "\" alt='' /></p>
<p>". twitter_parse_tags($text) . "</p>";
} else {
$content = "Damn! Something went wrong. Sorry :-("
."<br /> code=" . $code
."<br /> status=" . $status
."<br /> image=" . $image
."<br /> response=<pre>"
. print_r($tmhOAuth->response['response'], TRUE)
. "</pre><br /> info=<pre>"
. print_r($tmhOAuth->response['info'], TRUE)
. "</pre><br /> code=<pre>"
. print_r($tmhOAuth->response['code'], TRUE) . "</pre>";
}
} ?>
0
還有另外一個庫(它分叉),可以用於圖像上傳,請參閱:TwitterOauth
- 下載:Oauth File
- 使用代碼:
$path = '/absolute/path/to/background.jpg';
$meta = getimagesize($path);
$raw['image'] = $path.';type='.$meta['mime'];
$param['tile'] = 'true';
$status = $connection->post('account/update_profile_background_image',$param,$raw);
-1
最初我在提供媒體文件路徑時遇到了同樣的錯誤。實際上你需要提供字節讀取。因此請設置媒體參數如下所示,將工作:
$filename = "image.jpg";
$handle = fopen($filename, "rb");
$image = fread($handle, filesize($filename));
fclose($handle);
$params = array('media[]' => "{$image};type=image/jpeg;filename={$filename}" ,
'status' => 'my status');
$response =$twitteroauth->post('statuses/update_with_media', $params,true,true);
您可以訪問此鏈接,完整的參考http://net.tutsplus.com/tutorials/php/how-to-authenticate-users-with-twitter-oauth/
相關問題
- 1. 在twitter上使用php共享圖像
- 2. Twitter與SLRequest共享
- 3. Twitter共享問題
- 4. Android意圖ACTION_SEND_MULTIPLE與多個圖像共享在Twitter不工作
- 5. Twitter與文本共享圖像,烤麪包「圖像無法加載」
- 6. Android的共享圖像
- 7. 與Ionic共享圖像
- 8. 使用parse.com共享圖像
- 9. Eclipse項目共享圖像?
- 10. iphonesdk facebook圖像共享
- 11. iOS FacebookSDK圖像共享
- 12. Twitter共享不工作
- 13. 試圖與意圖共享圖像Android
- 14. Android:從原始文件夾共享圖像。錯誤的圖像共享
- 15. Android共享意圖Twitter:如何僅通過Tweet或Direct Message共享?
- 16. 如何與viewpager共享圖像意圖?
- 17. 開放共享圖像意圖
- 18. 在ios8中使用共享擴展共享圖像
- 19. 多個圖像不與社交共享插件共享Cordova/Phonegap
- 20. LinkedIn共享按鈕不刮圖像或共享內容
- 21. 在Twitter上共享沒有顯示圖片的縮略圖
- 22. 多個Facebook/Twitter/LinkedIn在單個頁面上共享不同內容的圖像
- 23. 共享視圖
- 24. Crystal Report:共享區域上的圖像
- 25. React Native - 與showShareActionSheetWithOptions共享本地圖像
- 26. 無法在android中共享圖像
- 27. Facebook的Android集成圖像共享
- 28. 如何共享ImageView的圖像?
- 29. 將圖像保存爲PDF共享點
- 30. 從Android應用程序共享圖像
謝謝!這個工作做得很好,稍微調整了一下,但是請注意,它不適用於新的Twitter API 1.1端點。 –
更新:得到它與API v.1.1一起工作,對於我以前的評論感到抱歉,您需要將端點url更改爲https://api.twitter.com/1.1/statuses/update_with_media.json –