简体   繁体   English

使用Twitter OAuth进行自动状态更新

[英]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. 我希望我的网站使用PHP中的OAuth自动将状态更新发布到特定的Twitter帐户。

I test this using a URL 我用URL测试了这个

www.mysite.com/update_status 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. 我试过保存oAuth令牌,但它没有用。

Thank you for your answer in advance! 感谢您提前给出答案!

My recommendation: 我的建议:

1) Use a PHP library like http://github.com/abraham/twitteroauth . 1)使用像http://github.com/abraham/twitteroauth这样的PHP库。

2) Select your app on http://dev.twitter.com/apps and click on "My Access Token". 2)在http://dev.twitter.com/apps上选择您的应用程序,然后单击“我的访问令牌”。

3) Us that access token as described on http://dev.twitter.com/pages/oauth_single_token . 3)我们访问令牌,如http://dev.twitter.com/pages/oauth_single_token所述

Just tried this and it WORKS! 刚试过这个就行了! And its SO SIMPLE to use!! 它的SO SIMPLE使用!!

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

Got it working in under 5mins. 在5分钟内完成工作。

xAuth is able to do that, but Twitter only allows it for desktop and mobile apps. xAuth能够做到这一点,但Twitter只允许它用于桌面和移动应用程序。
In case you wanna try it, read this article and the API docs . 如果您想尝试它,请阅读本文API文档

Try it with zend framework. 尝试使用zend框架。 As of version 1.10.8 minimal code required to post on Twitter is: 从版本1.10.8开始,在Twitter上发布的最小代码是:

$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 http://dev.twitter.com上注册您的应用程序后,可以访问所有令牌和机密

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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