[英]How to get twitter oAuth token of a logged in user
I'm trying to set up a javascript function to post a status to a twitter account using POST statuses/update, details here: https://dev.twitter.com/docs/api/1/post/statuses/update . 我正在尝试设置一个javascript函数,使用POST状态/更新将状态发布到Twitter帐户,详情请访问: https : //dev.twitter.com/docs/api/1/post/statuses/update 。 The goal is a Twitter post similar to the open graph actions on Facebook.
目标是一个Twitter帖子类似于Facebook上的开放图表操作。
I'm using jQuery ajax to make the post request, here's what I have so far: 我正在使用jQuery ajax来发布帖子请求,这是我到目前为止所拥有的:
$.ajax
({
type: "POST",
url: "https://api.twitter.com/1/statuses/update.json",
headers: jsonData,
data: {},
dataType: "jsonp",
success: function( data )
{
}
});
I believe that I need to generate a header something like this for security: 我相信我需要为安全性生成这样的标题:
Authorization: OAuth oauth_consumer_key=consumerKey, oauth_nonce=nonce,
oauth_signature=signature, oauth_signature_method="HMAC-SHA1",
oauth_timestamp=timestamp, oauth_token=userToken, oauth_version="1.0"
I have the consumer key for my app, I can generate a nonce, I'm generating the signature and timestamp using the methods from this question Twitter OAuth authentication in javascript . 我有我的应用程序的消费者密钥,我可以生成一个nonce,我正在使用javascript中的这个问题Twitter OAuth身份验证中的方法生成签名和时间戳。 The only thing I have left is th oauth_token, which I believe is the token of the user whose feed I wish to post to.
我唯一留下的是oauth_token,我认为这是我希望发布的用户的标记。 Please correct me if I'm wrong about that.
如果我错了,请纠正我。
The problem is, I have absolutely no idea how to get this token from the user in order to post to their feed. 问题是,我完全不知道如何从用户那里获取此令牌以便发布到他们的Feed。 I've spent the last 2 hours running around in circles through Twitter's oAuth documention without finding anything that looked useful;
我花了最后2个小时在Twitter的oAuth文档中乱跑,没有找到任何看起来有用的东西; everything I've found was either flowcharts with no code examples or predicated on my code already having the user's oAuth token.
我发现的一切都是没有代码示例的流程图,或者是我的代码已经拥有用户的oAuth令牌。
My question is this: how can I get the logged in user's oAuth token using javascript? 我的问题是:如何使用javascript获取登录用户的oAuth令牌?
If that is not possible, I have another page where I am currently storing the user's twitter id in the database with their permission, getting their token and databasing it in PHP would also be satisfactory, assuming it doesn't change very frequently. 如果那是不可能的,我有另一个页面,我目前正在他们的权限中将用户的twitter id存储在数据库中,获取他们的令牌并在PHP中进行数据库处理也是令人满意的,假设它不会经常更改。
In order to obtain the oauth_token you need to follow the authentication process. 为了获得oauth_token,您需要遵循身份验证过程。 Your application needs to be authorized to act on the behalf of the user.
您的应用程序需要被授权代表用户行事。 I would recomend to take some time first and learn how OAuth exactly works (there is a lot of information available) and then implement it in your app.
我建议先花一些时间来了解OAuth的确切工作原理(有很多可用的信息),然后在你的应用中实现它。 ( http://hueniverse.com/oauth/ ) You could also benefit from a library which will make your life easier.
( http://hueniverse.com/oauth/ )您也可以从图书馆中受益,让您的生活更轻松。 (in your case, look at: https://dev.twitter.com/docs/twitter-libraries#php ).
(在您的情况下,请查看: https : //dev.twitter.com/docs/twitter-libraries#php )。
Hope this has been useful. 希望这有用。
Here is example for get twitter oauth token and post tweet in twitter . 以下是获取twitter oauth令牌并在Twitter上发布推文的示例。 Code sample is in php .
代码示例在php中。
http://www.phpgang.com/how-to-post-tweet-on-twitter-with-php_414.html http://www.phpgang.com/how-to-post-tweet-on-twitter-with-php_414.html
1) to obtain the oauth token you need to follow the authentication process. 1)获取oauth令牌,您需要遵循身份验证过程。
2) and your application needs to be authorized to act on the behalf of the user. 2)并且您的应用程序需要被授权代表用户行事。
you can also see this twitter example for better understanding how it works 您还可以看到这个Twitter示例,以便更好地了解它的工作原理
In this use can see the process of authorized user and post and get json result. 在这个用途中可以看到授权用户的过程和发布并获得json结果。
https://dev.twitter.com/rest/tools/console https://dev.twitter.com/rest/tools/console
I hope this will help you. 我希望这能帮到您。
thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.