下面的代码我用于将图片发布到Twitter但没有发生任何事情,真的发布文本很容易,但发布图片没有,我搜索但没有正确的结果:
<?php
include ("OAuth.php");
include ("twitteroauth.php");
include ("tmhOAuth.php");
include ("tmhUtilities.php");
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'SDKFJDKSLFJLAKSDFJLKSDJFLKSDJFKLS09RYER;',
'consumer_secret' => 'JSDFLKDJSFLKDSJFLKJSDKLFJDLKFJKLDFJKLSDJF',
'user_token' => '93593-SDLKFJSDLKFJKLSDFJKLSDJFKLSDJFLKSDF',
'user_secret' => 'KSDJFKLSDJFR93490E90RI90WEIR90EIEIF9DIF',
));
$image = 'image.jpg';
$code = $tmhOAuth->request( 'POST','https://upload.twitter.com/1/statuses/update_with_media.json',
array(
'media[]' => "@{$image};type=image/jpg;filename={$image}",
'status' => 'message text written here',
),
true, // use auth
true // multipart
);
if ($code == 200){
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
}else{
tmhUtilities::pr($tmhOAuth->response['response']);
}
return tmhUtilities;
?>
如果有任何错误,请告诉我,请伙计们,我需要它,谢谢你的帮助
答案 0 :(得分:0)
您的请求对象设置错误以此为例进行修复。
$params = array(
'media[]' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
'status' => $_POST['status']
);
$code = $tmhOAuth->user_request(array(
'method' => 'POST',
'url' => $tmhOAuth->url("1.1/statuses/update_with_media"),
'params' => $params,
'multipart' => true
));
答案 1 :(得分:0)
update_with_media
的工作原理是将图片的网址附加到推文的末尾。在Twitter上,显示URL上的图像。由于Twitter上的URL为22个字符(对于HTTP)或23个字符(对于HTTPS),因此您的状态不能超过140-22或140-23个字符。使您的状态少于117个字符,然后重试。
如果这不起作用,那么它可能是库的问题。我建议使用CodeBird。