I'm trying to implement an upload_with_media request from ajax using Abraham's twitteroauth library (TwitterOAuth v0.2.0-beta2). I've had no problems with basic posts but when I try to include media I get this as a response:
"{"request":"\/1\/statuses\/update_with_media.json","error":"Error creating status."}"
My code for posting media looks like this:
$image = $_FILES["media"]["tmp_name"];
$parameters = array(
'media[]' => "@{$image};type=image/jpeg;filename={$image}",
'status' => $status
);
if(isset($reply_id)) {
$parameters['in_reply_to_status_id'] = $reply_id;
}
$post = $twitteroauth->post('https://upload.twitter.com/1/statuses/update_with_media.json', $parameters);
echo json_encode($post);
I have verified that all data is being sent to this script correctly and even managed to get an update_with_media post working using the same data above and the tmhOAuth library but as the rest of my widget uses twitteroauth, I'd prefer to keep things uniform. I've also tried it with and without the .json affixed to the ending and saw no difference. Can anyone show me an example of a successful implementation of update_with_media using twitteroauth? I can't seem to figure out what I'm doing wrong.
The original library doesn't include uploading media functionality yet. You may check out https://github.com/natefanaro/twitteroauth .
After dealing during hours for a solution to UPDATE_WITH_MEDIA with twitteraouth library, I found the following solution that works fine:
IS NOT WORKING WITH UPDATE_WITH_MEDIA
The basic diference is that the original has the function "post" without "$multipart" parameter. This parameter is what allows to send what Twiiter ask for in the documentation: a multipart enctype post. So at the end the basic code is as follows:
IMPORTANT! If you try this code with the original library, you will find out an error. You have to download from the link above and replace both files (OAuth.php and twitteroauth.php) in your project.
Try using codebird-php https://github.com/mynetx/codebird-php
It turn out that it does the trick despite being last in the list of php libraries suggested by Twitter. Just grab codebird.php and cacert.pem from the git repo.
I want to sent url link with status param
like : Put you message here
I suggest that you use Fiddler2 or some similar tool to examine and compare the messages that go out with twitteroauth, and also with tmhOAuth. You will see the difference.
In my experience, this is what an HTTP POST to Twitter looks like, using update_with_media.{xml,json}. The suffix you use affects only the respponse, I believe. (Your app must set the Authorization header in a way that is specific to your app.)
You want to get twitteroauth to post something like the following