Twitter with PHP and image working once only


#1

I used this PHP to tweet a message and attached a picture

<?php
error_reporting(E_ALL);

require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => '***************',
  'consumer_secret' => '***************',
  'user_token'      => '***************',
  'user_secret'     => '***************',
));

$image = '1329929312.jpg';
 
$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
  array(
    'media[]'  => "@{$image}",
	"status"   => "Is this working now?"
  ),
  true, // use auth
  true  // multipart
);
 
if ($code == 200) {
  tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
  tmhUtilities::pr($tmhOAuth->response['response']);
}
?>

But after tweeting once successfully, with image and message all as expected, it stopped working again.

When I try now there are no response at all that I can look at and debug from, and I don’t think I have changed anything in the php since it worked.
Anyone here able to see what went wrong?


#2

Tried to grab the code from this too https://dev.twitter.com/discussions/1059 does not work either, downloaded everything from GIT again to make sure it was unchanged too, still no luck.

Tried new keys, tried to create a new app, nothing… Difficult to debug on when getting no replies.


#3

Are you trying to POST the same status and image each time? Duplicate attempts should be avoided. Our API will always give you a response of some kind – at least a status code with a message – you should look for this to give more of a hint as to what is amiss.


#4

No, it is a different status, and a different image. Both image and image name are different too.

Tried a few different php libraries now.


This one tells me “Could not connect to Twitter. Refresh the page or try again later.” but I don’t see any problems when trying to access the same url’s it is using, so not sure if it just just the library or something else that is wrong.


#5

Problem found! Was the certificate file that for some unknown reason got corrupted, file moved, problem solved.


#6

Glad you got it figured out.


#7

i want to share image on twitter using PHP script so someone please show me the current way…!:slight_smile:


#8

i have used same script,but not working.Any one can help??


#9

all i am getting is 0 no message no response or object


#10

Hi Taylor! Please can you tell me how can I post the SAME status each time? I need it just for testing purposes. I need to test Cron task sheduler on my server and reuploading a new file each time is butthurt :slight_smile: Sorry for noob question, I’m just making my first steps in programming. Thank you beforehand!


#11

if you want to tweet images using twitter api you can check our blog to see all the steps and download the example:


#12

I am getting 400 error.how to resolve this issue? (API v1.1)


#13

hi,

I am also getting the same problem . Have you found the solution ? If so please help me too.


#14

I’m already trying for hours to fix this problem and still don’t found an answer the script is just giving no respons at all

<?php require 'tmhOAuth.php'; require 'tmhUtilities.php'; $tmhOAuth = new tmhOAuth(array( 'consumer_key' => '', 'consumer_secret' => '', 'user_token' => '', 'user_secret' => '', )); // we're using a hardcoded image path here. You can easily replace this with an uploaded image-see images.php example) // 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}", $image = './dickvandyke.jpg'; $code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1.1/statuses/update_with_media.json', array( 'media[]' => "@{$image}", 'status' => "Don't slip up" // Don't give up.. ), true, // use auth true // multipart ); if ($code == 200) { tmhUtilities::pr(json_decode($tmhOAuth->response['response'])); } else { tmhUtilities::pr($tmhOAuth->response['response']); } ?>

#15

The domain name for statuses/update_with_media.json changed to api.twitter.com (instead of upload.twitter.com) a number of months ago – it might be why you’re having trouble.


#16