允许我的应用程序用户从单个帐户发布推文
我有一个小应用程序,可以显示我的小国家:比利时的公共交通交通问题。
例如,我在应用程序中创建了一个系统,允许用户在火车延误时警告所有人。
我想做的是允许我信任的用户从我的帐户发推文,例如“用户 X 说 123456 号火车晚点 3 分钟”,
所以基本上,我想在代码中硬编码 Twitter 用户名和密码并发送推文,因为我拥有所有凭证。 (基本上,我还会检查我是否每小时只发布 1 或 2 条推文)
我已阅读 Twitter 文档,但找不到任何相关信息。
它认为通过 php 是可能的:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "{$twitter_user}:{$twitter_password}");
从这里: http://www.webmaster-source.com/2009/04/05/post-to-twitter-from-a-php-script/
I have a small application that display traffic issues on public transportation in my small country: Belgium.
I made a system in the application that allow users to warn all people when there is delay on the trains, for instance.
What I would like to do is to allow my trusted users to tweet from my account something like "User X said 3 minutes delay on train 123456"
SO basically, i would like to hardcode the twitter username and password in the code and send the tweet, as I have all the credentials. (basically, I would also check that I post only 1 or 2 tweets an hour)
I have read the twitter documentation, but couldn't find any information on that.
It think that's possible via php:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "{$twitter_user}:{$twitter_password}");
from here: http://www.webmaster-source.com/2009/04/05/post-to-twitter-from-a-php-script/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须拥有自己的服务器来供应用程序发送消息。收到消息后,您的应用程序将使用 oauth 登录 twitter 并 使用您的凭据发布消息。
有适用于许多不同语言和 Web 应用程序的 twitter 和/或 oauth 库,因此设置应该很容易。
如果您选择这条路线,您应该在 Twitter 上注册您的(服务器)应用,然后您将拥有您开始使用所需的密钥。
You would have to have your own server that the application sends messages to. Upon receipt of a message, your app would then use oauth to log in to twitter and post the message using your credentials.
There are twitter and/or oauth libraries available for a lot of different languages and web apps, so it should be pretty easy to set something up.
If you go this route, you should register your (server) app on twitter, and then you'll have the keys you need to get started.
您必须授权 Twitter 用户。不再允许以前的
username
和password
curl方法。您应该为此运行一个 cron 作业。当用户叹气时,您保存他们的身份验证参数,您可以在此处查看允许您轻松执行此操作的库。
Twitter 库
You have to authorize the twitter users. The former
username
andpassword
curl method is no longer allowed. You should run a cron-job for this. When the users sigh in you save their authentication paramatersYou can check here for libraries that allow you do this easily.
Twitter Library
你不能这样做。由于 Twitter API 有速率限制,因此您无法发送无限制的 API 请求。您每小时最多可以有 350 个请求。如果多个用户尝试使用同一帐户,该帐户将在几分钟内跨越速率限制
You can't do this. As Twitter API has rate limit, you can't send request unlimited API requests. You can have maximum 350 requests per hour. The account will cross rate limit within a few minutes if number of user tries to use the same account