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