简体   繁体   中英

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.')); 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM