简体   繁体   English

如何检查Twitter OAuth access_token是否仍然有效?

[英]How do I check if a Twitter OAuth access_token is still valid?

I'm writing a Django app and I want users to be able to supply their Twitter username and connect their Twitter account with their User in my app. 我正在编写Django应用,我希望用户能够提供其Twitter用户名,并将其Twitter帐户与我的应用中的User连接。 (I'm not using Twitter to log them into my site; I just want them to connect their Twitter account with their account on my site, and give permissions for certain actions.) (我不是在使用Twitter将他们登录到我的网站;我只是希望他们将其Twitter帐户与他们在我的网站上的帐户相关联,并为某些操作提供权限。)

Assuming I do that successfully, and I get back and store an access_token for the user, what's the best way to subsequently check that the access_token is still valid? 假设我成功完成此操作,然后返回并为用户存储了一个access_token,那么随后检查该access_token仍然有效的最佳方法是什么? ie, if the user has later revokes access to my service on their Twitter account, I want to be able to check the access_token and, if it's invalid, delete it and prompt the user to re-authenticate. 即,如果用户以后撤消了其Twitter帐户上对我的服务的访问权限,则我希望能够检查access_token,如果无效,则将其删除并提示用户重新进行身份验证。

The Flickr API has flickr.auth.checkToken and I guess I'm looking for the equivalent functionality with the Twitter API. Flickr API具有flickr.auth.checkToken ,我想我正在寻找与Twitter API等效的功能。

使用python-twitter,您可以使用以下方法验证凭据是否正确:

if api.VerifyCredentials() is not None:

暂无
暂无

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

相关问题 在哪里可以使用Twitter的access_token和token_secret - Where I can take access_token and token_secret for twitter 当我尝试请求OAuth access_token时,我得到:TypeError:encode()参数1必须是字符串,而不是None - When trying to request for OAuth access_token I get: TypeError: encode() argument 1 must be string, not None django社交认证从Google oauth2获得错误的access_token - django social auth get wrong access_token from google oauth2 如何读取Facebook access_token返回的JSON数据 - How to read JSON data return by the Facebook access_token django-socialregistration access_token错误 - django-socialregistration access_token error 当我尝试获取 access_token 时,Python-social-auth 管道返回 TypeError - Python-social-auth pipeline returns TypeError when I'm trying to get access_token Django Rest Framework API如何从请求中提取access_token? - Django Rest Framework API How to extract access_token from request? Twitter / Tweepy OAuth - 如何保存 oauth_token 以在 REST3A814634A 设置中的回调中验证它 - Twitter / Tweepy OAuth - How to save oauth_token to verify it on callback in a REST API setup Django自定义中间件检查标头令牌。使用有效请求标头令牌的测试仍然失败 - Django custom middleware to check header token.Tests with valid request header tokens still fails 在python或django本身过期时自动生成access_token - Auto generate an access_token when expired in python or django itself
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM