简体   繁体   English

Twitter API:在不发送用户名/密码的情况下获取访问令牌

[英]Twitter API: Get Access Token without sending username/password

I am having a problem obtaining the twitter users access token and secret token without sending a username and password . 我在不发送用户名和密码的情况下获取twitter用户访问令牌和秘密令牌时遇到问题 I would like to get the access token by just sending the twitter_id, once the user has already authenticated my application before. 一旦用户之前已经对我的应用程序进行身份验证,我想通过发送twitter_id来获取访问令牌。

So the scenario is: 所以场景是:

A user logs into my site (using custom login), he already gave my application permission to read/write his tweets. 一个用户登录到我的网站(使用自定义登录),他已经向我的应用程序授予了读/写其推文的权限。 Now I need to load this users access token and secret access token. 现在,我需要加载此用户的访问令牌和秘密访问令牌。

Database:
CustomUID : 1 , Twitter_ID: 123456.  

So Since I know CustomUID 1 is logged in, I need the access token/secret from Twitter_ID:123456. 因此,由于我知道CustomUID 1已登录,因此我需要来自Twitter_ID:123456的访问令牌/秘密。

The Problem is I can´t find an API function that would let me get the access token without being redirect to Twitter Callback function (Twitter landing page), where the user has to type in his/her username and password, once again because the Request Tokens are obtained by the URL. 问题是我找不到一个API函数,该函数无需重定向到Twitter回调函数(Twitter登陆页面)就可以获取访问令牌,在该函数中,用户必须输入其用户名和密码,这再次是因为请求令牌是通过URL获得的。

How can I solve this problem? 我怎么解决这个问题? I am used to the Facebook API, where user which have already authorize my app, allow me to receive their accesstoken just bei sending getAccessToken($ID) . 我已经习惯了Facebook API,已经授权我的应用程序的用户可以通过发送getAccessToken($ ID)来接收他们的访问令牌。

Thank you very much for help! 非常感谢您的帮助!

You have to save, possibly in your DB, the OAuth token and access token after the first time the user authenticates. 用户首次验证后,您可能必须在数据库中保存OAuth令牌和访问令牌。 Then retrieve the token the next time you need to perform a query on behalf of that user. 然后,下次您需要代表该用户执行查询时,检索令牌。

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

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