通过 PHP 私下发推文
我一直在看 twitter api。但我有点迷失了。我想使用一个简单的 Web 表单(1 个输入,1 个按钮)从 PHP 发送推文,这是我和使用同一帐户的妻子的 LAN 的专用系统。即使我知道我已经想发推文了,我还需要完成整个 OAuth 流程吗?
这纯粹是为了发推文,除了关于它是否有效的真或假之外,我不想返回任何内容。
I have been looking at the twitter api. I'm kind of lost though. I want to tweet from PHP using a simple web form (1 input, 1 button), this is a private system for my LAN for me and the wife who use the same account. Do I still need to go through the whole OAuth process even though I know I want to tweet already?
This is purely for tweeting, I dont want to return anything except maybe a true or false as to whether it worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Twitter 为创建应用程序的帐户提供获取访问令牌的流程。如果您使用您想要发推文的帐户登录 https://dev.twitter.com/apps然后单击您要使用的应用程序的名称(如果您还没有,请先创建一个)。您应该知道位于应用程序详细信息页面 (.com/apps/123),而不是应用程序设置页面 (.com/apps/edit/123)。右侧是“我的访问令牌”选项,它将为您提供访问令牌和访问令牌密钥。这些的作用类似于帐户的密码。
下载最新版本的 TwitterOAuth(当前为 0.2.0-beta3)并放置
twitteroauth目录中的 .php
和OAuth.php
文件。将以下代码放入同一目录中的 php 文件中,将四个字符串值替换为应用程序和访问令牌中的相应值。您现在可以向 php 文件提交表单,将文本传递给
post()
函数,它将发布一条新推文。Twitter provides a process for getting an access token for the account that created the application. If you log into https://dev.twitter.com/apps with the account you wish to tweet from and click the name of the app you wish to use (create one first if you don't already have one). You should know be on the application details page (.com/apps/123) not on the application settings page (.com/apps/edit/123). On the right is a My Access Token option which will give you an access token and an access token secret. These will act similar to a password for the account.
Download the latest version of TwitterOAuth (currently 0.2.0-beta3) and place the
twitteroauth.php
andOAuth.php
files in a directory. Place the following code in a php file in the same directory replacing the four string values with the corresponding values from your app and your access token.You can now submit a form to the php file, pass the text to the
post()
function and it will post a new tweet.您必须至少经过一次,但由于身份验证目前尚未过期,因此您可以执行一次“舞蹈”,然后对应用程序中的各种代码进行硬编码。您确实需要至少执行一次(注册您的应用程序、允许您的应用程序使用您的帐户、获取代码等),否则当然不会告诉您知道密码。
You have to go trough it at least once, but as the authentication doesn't expire at the moment, you can do the "dance" once, and then hardcode the various codes in your app. You do need to do it at least once (register your app, allow your app to use your account, get the code, etc), otherwise there's no telling you know the password of course.
由于您使用的是单一帐户,因此您只需执行一次 OAuth 身份验证。我使用 API 为我的雇主 (pittnews.com) 发推文,他们有大约 14 个人使用相同的 OAuth 身份验证从同一帐户发推文。我将这些值存储在用于发推文的 PHP 中。
Since you are using a singular account, you will only need to perform the OAuth authentication once. I use the API to tweet for my employers (pittnews.com) and they have about 14 people tweet from the same account using the same OAuth authentication. I store the values in the PHP I utilize for tweeting.
您必须默认设置一个帐户并使用此帐户...(将其保存在conf文件中并包含在php文件中,如果您的帐户过期,请使用下面的类进行新会话)
请参阅此类
你也可以查看 api 手册
you must set one account by default and use this account... ( save it in conf file and include in php file and if your account expired use below class for new session )
see this class
also you can see api manual
是的,您需要最终获得应用程序的 OAuth 访问令牌密钥才能访问您的 Twitter 帐户,然后才能开始发推文。由于您使用的是 PHP,我建议在 中使用 Twitter 支持Zend 框架。它可以帮助您执行 OAuth shuffle,还可以执行一般的 Twitter 功能。
Yes, you need to ultimately obtain an OAuth access token secret for your app to access your Twitter account before you can start tweeting. Since you're using PHP, I'd suggest using the Twitter support within the Zend framework. It can help you perform the OAuth shuffle, and also perform the general Twitter functions.