简体   繁体   English

如何获取登录用户的twitter oAuth令牌

[英]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.

相关问题 使用oauth_token和oauth_token_secret如何使用Twitter API获取用户详细信息? - Using oauth_token and oauth_token_secret how to get user details with twitter api? 在任何地方使用Twitter获取oauth_token和oauth_token秘密 - get oauth_token and oauth_token secret with twitter anywhere 用户登录时如何从前端获取身份验证令牌 - How to get authentication token from front end while the user is logged in ng-token-auth获得登录用户 - ng-token-auth get logged in user Twitter API调用仅使用javascript获取OAuth的access_token - Twitter API call to get access_token of OAuth only with javascript 用户登录并在Google OAuth2中同意后,如何获取访问令牌和刷新令牌? - How to get access token and refresh token after user login and consent in Google OAuth2? 如何以编程方式(使用JS / PHP)为github用户获取curl“授权令牌(OAuth令牌)”? - How to get curl “Authorization token(OAuth token)” programmatically (using JS/PHP ) for github user? JavaScript中的Twitter OAuth请求令牌 - Twitter OAuth Request Token in JavaScript 如何使用oauth使Twitter获得请求? - How to make a twitter get request using oauth? 如何使用ajax和jquery将twitter oauth令牌放入标头中 - how to put twitter oauth token in header using ajax and jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM