Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting a Tweet using Oauth

I'm trying to create a web application that will allow a user to post a tweet from a form directly on the webpage, instead of using Twitter's own pre-built pop-up. The problem is, the snippet of code that I'm seeing around the web is not working:

$message = "Hello there! This is a tweet!";

$twitterObj->post('statuses/update', array('status' => "$message"));

And when I try to execute the code I get this error:

Warning: Invalid argument supplied for foreach() in /twitter/EpiOAuth.php on line 76

Warning: http_build_query() [function.http-build-query]: Parameter 1 expected to be Array or Object. Incorrect value given in /twitter/EpiOAuth.php on line 140

I'm building off the example and using the OAuth library found at this web address:

http://www.jaisenmathai.com/articles/twitter-php-sign-in.html

Does anyone have any tips?


EDIT

Problem solved! It turns out that this was the correct statement that I needed to use:

$twitterObj->post_statusesUpdate(array('status' => 'Message goes here.'));
like image 470
Jose Garza Avatar asked Nov 05 '22 00:11

Jose Garza


1 Answers

This is what I use:

$message = "Hello there! This is a tweet!";

$twitterObj->OAuthRequest('https://twitter.com/statuses/update.xml', array('status' => $message), 'POST');

This is with the library found here: https://github.com/abraham/twitteroauth

like image 90
Hawkee Avatar answered Nov 09 '22 13:11

Hawkee