0

Is there a good Samaritan that can give the working code for uploading photos to twitter using PHP website?

I have searched a lot but it's not working for me. I don't know if I missed to add something or the code is not functioning well anymore.

I'm open for any link to that tutorial for this matter.

thanks in advance.

Sam San
  • 6,567
  • 8
  • 33
  • 51

1 Answers1

0

You'll need the tmoauth library from twitter. I can't explain how to implement within your code, but this is cut and pasted from my working code, but I had to anonymize some stuff.

//THIS IS THE CREDS FOR TWITTER - I HAVE THEM IN AN ARRAY
    $tmhOAuth = new tmhOAuth(array(
       'consumer_key'    => $network_array['consumer_key'], 
       'consumer_secret' => $network_array['consumer_secret'],
       'user_token'      => $network_array['user_token'],
       'user_secret'     => $network_array['user_secret']
      ));
     }

//PARAMS UNIQUE FOR THIS TWEET
       $params = array(
      'media[]' => '@' . $process_image['image_path'],  //PATH TO IMAGE
      'status' => $tweet_response,  //THIS IS THE TEXT WE USE FOR THE TWEET
      'in_reply_to_status_id' => $mentions[$c]["id"]  //IF REPLYING, IT'S HERE
       );

//THIS IS HOW YOU TELL TWITTER IT'S A PHOTO

       $code = $tmhOAuth->user_request(array(
      'method' => 'POST',
      'url' => $tmhOAuth->url("1.1/statuses/update_with_media"),
      'params' => $params,
      'multipart' => true
       ));
ssaltman
  • 3,623
  • 1
  • 18
  • 21