media_ids ignored in POST request to statuses/update


#1

For some reason, the media_ids parameter is being ignored. I’ve look through other topics, but there doesn’t seem to be a concrete answer.

I’m using the TwitterAPIexchange.php library, here is sample code:

$url = 'https://api.twitter.com/1.1/statuses/update.json';
$postfields = array(
	"media_ids" => 586661110067114984,

	"status" => "So we keep on testing!"
);

$requestMethod = 'POST';

echo $twitter->setPostfields($postfields)
         ->buildOauth($url, $requestMethod)
         ->performRequest();  

Thank you for your help!

EDIT: The status gets updated but without the image.


Media_ids parameter ignored with status update
#2

Hi, I was having this problem as well, and earlier I saw another person post this who also had the same problem and was using the same library.

When I saw your post I realised it might be a problem with the library, so I tried tmhOauth instead which worked fine for me. I can’t say why it doesn’t work for J7mbo/twitter-api-php, maybe something to do with the http headers.

I used the example script here for uploading media with tmhOauth and then creating a tweet with the attached media.

Hope that helps

Joe


#3

Hello, thanks, I actually ended up writing my own library to fix the issue.

I think I’m going to document it and make it availably publicly.


#4

OK, so I ended created my own library to work around the issue.

So now, to upload a media file I simply use:

$media_path = "/path/to/media/";
$response = $twitter->media($media_path);

//Convert to an object from the JSON response
$media_response = json_decode( $response );

//Get the media id:
$media_id = $media_response->media_id;

//Update the status
$url = "https://api.twitter.com/1.1/statuses/update.json";
$params = array (
                 'status' => 'Here is my new status!',
                 'media_ids' => $media_id
                );

 $twitter->params( $params );
 $response = $twitter->post( $url );

If you’d like to use my code, here is the link to the library => Easy Twitter API Library.


#5

I’ll have to check out this library and test this scenario. Not sure what the issue is, but off the top of my head, do you know if your server can handle 64 bit numbers? Does the media_ids value echo as expected? You can check the maximum integer by running php -r 'echo PHP_INT_MAX;'. You can certainly pass the media_ids as a string if that is the problem.


#6

You need to get the media id from media/upload … Media ID’s don’t live forever.

You don’t mention where the media ID you are sending is coming from - if it is from some previous upload that you are trying to use again - I’m afraid that won’t do.

If the media id you are talking about is coming from a current media/upload response - then I’m not being very helpful.


#7

The media_id is from the current response.


#8

That was not the issue, the issue was from the way the request was constructed.