开发者

Using Twitter OAuth for automatic status update

I want my website to automatically post status updates to a particular twitter account using OAuth in PHP.

I test this using a URL

www.mysite.com/update_status

but it asks me for "user name" and "password", which is fine when I am testing it. But my website will not be able to insert this user name and password before posting the status update.

So the question is how can a website which is in the server, automatically post a status update to an account without user filling out the user name and password.

Is there any开发者_如何学运维 way to bypass this? I tried saving oAuth tokens, but it's not working.

Thank you for your answer in advance!


My recommendation:

1) Use a PHP library like http://github.com/abraham/twitteroauth.

2) Select your app on http://dev.twitter.com/apps and click on "My Access Token".

3) Us that access token as described on http://dev.twitter.com/pages/oauth_single_token.


Just tried this and it WORKS! And its SO SIMPLE to use!!

http://ditio.net/2010/06/07/twitter-php-oauth-update-status/

Got it working in under 5mins.


xAuth is able to do that, but Twitter only allows it for desktop and mobile apps.
In case you wanna try it, read this article and the API docs.


Try it with zend framework. As of version 1.10.8 minimal code required to post on Twitter is:

$token = new Zend_Oauth_Token_Access;
$token->setParams(array(
'oauth_token' => 'REPLACE_WITH_TOKEN',
'oauth_token_secret' => 'REPLACE_WITH_TOKEN_SECRET'
));

$twitter = new Zend_Service_Twitter(array(
'consumerSecret' => 'REPLACE_WITH_CONSUMER_SECRET',
'accessToken' => $token
));

$response = $twitter->status->update('REPLACE WITH MESSAGE');

All tokens and secrets can be accessed after registering your application on http://dev.twitter.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜