Using Twitter OAuth for automatic status update

2019-03-27 19:31发布

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!

4条回答
姐就是有狂的资本
2楼-- · 2019-03-27 20:02

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.

查看更多
够拽才男人
3楼-- · 2019-03-27 20:03

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.

查看更多
劫难
4楼-- · 2019-03-27 20:11

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

查看更多
祖国的老花朵
5楼-- · 2019-03-27 20:16

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.

查看更多
登录 后发表回答