使用Oauth发布推文

时间:2012-05-07 16:31:13

标签: php html forms twitter oauth

我正在尝试创建一个Web应用程序,允许用户直接在网页上发布表单中的推文,而不是使用Twitter自己预先构建的弹出窗口。问题是,我在网络上看到的代码片段无法正常工作:

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

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

当我尝试执行代码时,我收到此错误:

警告:在第76行的/twitter/EpiOAuth.php中为foreach()提供的参数无效

警告:http_build_query()[function.http-build-query]:参数1应为Array或Object。第140行/twitter/EpiOAuth.php中给出的值不正确

我正在构建示例并使用此网址上的OAuth库:

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

有没有人有任何提示?

<小时/> EDIT

问题解决了!事实证明,这是我需要使用的正确陈述:

$twitterObj->post_statusesUpdate(array('status' => 'Message goes here.'));

1 个答案:

答案 0 :(得分:2)

这就是我使用的:

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

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

这是在这里找到的库:https://github.com/abraham/twitteroauth