PHPoAuthLib
PHPoAuthLib copied to clipboard
how to upload media to twitter use PHPoAuthLib?
Hi guys, this library is so awesome and just discard other php oauth libs.
i try to upload img to twitter:
$result = $service->request( "/statuses/update_with_media.json", "post",
array (
'status' => $share->getMsg(),
'media[]' => file_get_contents( $share->getImg() )
), array (
'Content-type' => 'Content-type: multipart/form-data'
) );
seems not working, can anyone help?
Hey there,
Just wanted to let you know I've patched this in pull #297 to allow multipart transfers to work.
The syntax is a bit different now due to the way PHP's cURL library has changed, if you were to clone my changes then your request would look like this. I have fixed your content-type header too, the prefix is added further inside the library.
$result = $service->request( "/statuses/update_with_media.json", "POST",
array(
'status' => $share->getMsg(),
'media[]' => new CURLFile($share->getImg(), mime_content_type($share->getImg()), 'media[]')
), array(
'Content-type' => 'multipart/form-data',
// cURL will add this automatically when we do a file upload, and twitter will explode if it's present in the request headers.
'Expect' => '',
)
);
You might also have to force use of cURL, I found that my install was always choosing the stream method which is likely incapable of transferring binary data. I could be wrong though. I achieved this by creating a new OAuth\ServiceFactory
and calling the setHttpClient()
method on it when registering the OAuth service provider.
Hi,
I'm having the same issue, I've set the Http Client to use curl, but getting the following response from Twitter
{"errors":[{"message":"Could not authenticate you","code":32}]}
My code looks like this
$result = $twitterService->request( "/statuses/update_with_media.json", "POST", array( 'status' => "hello", 'media[]' =>file_get_contents($image) ) , array( 'Content-Type' => 'multipart/form-data',
'Expect' => '',
)
);
Any ideas what the issue is? I've regenerated my API keys as I thought it was a permissions issue but still getting the same response.
hey @jimwib, did you manage to make it work?
No, still having the same problems
@jimwib I think that URL you're trying to hit is wrong, at least according to Twitter API docs, it should be https://upload.twitter.com/1.1/media/upload.json. But I get Authorization Error, with it, as well.
Yes, I'm getting this Authorization error, no matter what URL try to hit: https://api.twitter.com/1.1/statuses/update_with_media.json, this one doesn't work either.
I was wondering if it was something to do with the way the library assembles the request thats causing the issue
yea, not sure, could be, I'll let you know, in case I find some solution.
Hey dudes, can you reproduce an issue on the updated library?
I'm still having this problem myself, I get a "Could not authenticate you." When trying to upload an image with my tweet. Regular Tweets work fine. Did anyone come up with a solution for this they could point me toward?