When trying to call the twitter media upload resource using PECL OAuth, I noticed the API call was failing. I later found out that the reason was that the wrong content-type was sent. The header contained Content-Type: application/x-www-form-urlencoded
instead of the required Content-Type: multipart/formdata
.
To set the content type to multipart when using PECL OAuth, the request engine needs to be set to use cURL instead of PHP Streams as multipart is only supported by the former. Also if sending a media file, @
needs to be prepended to both the file and parameter name.
$oauth = new OAuth( $consumerKey, $consumerSecret ); $oauth->setRequestEngine( OAUTH_REQENGINE_CURL ); $oauth->setToken( $token, $secret ); $status = 'This is a test'; $image = './test.jpg'; $oauth->fetch( 'https://upload.twitter.com/1/statuses/update_with_media.json', array( '@media[]' => '@' . $image, 'status' => $status ), OAUTH_HTTP_METHOD_POST );
Hi David,
I’m running with your codes but it returns error 400.
Can you help me how to fix this?
Hi!
I’m having the same issue.
When I send only one value in the array, I get a valid response but as soon as I pass more than one, I get Failed to validate Signature.
Here’s a sample code I have:
Hi Stephen,
You might need to check the API doc to make sure the request accepts an array with more than one value.
Hi
it dosent help, i see the header remain
Content-Type: application/x-www-form-urlencoded
Do you have the cURL extension installed? This might help http://goo.gl/WCEJj.