如何在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. 没有Twitter图标Twitter分享按钮,只需共享
- 5. Android意图ACTION_SEND_MULTIPLE与多个图像共享在Twitter不工作
- 6. 将图像添加到Twitter共享意图Android
- 7. 分享链接,标题和自定义Twitter共享图标一个图像
- 8. 无法发布图像到Twitter使用共享包
- 9. FB,TWITTER,G +共享网址和固定预览图像
- 10. 如何在twitter上使用unity3d共享图像
- 11. 在Twitter上使用javascript共享base64图像
- 12. Twitter与文本共享图像,烤面包“图像无法加载”
- 13. Instagram的iPhone共享图像
- 14. 的Android PlusClient共享图像
- 15. 从SD卡共享图像
- 16. 共享图像不刷新
- 17. 图像共享功能
- 18. Facebook SDK 3.1 - 共享图像
- 19. Eclipse项目共享图像?
- 20. iOS FacebookSDK图像共享
- 21. 图像共享在IOS
- 22. UIActivityViewController共享多个图像
- 23. 使用parse.com共享图像
- 24. Android的共享图像
- 25. iphonesdk facebook图像共享
- 26. 仅从Twitter获取共享?
- 27. Twitter共享不工作
- 28. Android共享意图共享图像不存在
- 29. 意图共享不与图像和文本共享
- 30. 试图与意图共享图像Android
谢谢!这个工作做得很好,稍微调整了一下,但是请注意,它不适用于新的Twitter API 1.1端点。 –
更新:得到它与API v.1.1一起工作,对于我以前的评论感到抱歉,您需要将端点url更改为https://api.twitter.com/1.1/statuses/update_with_media.json –