我创建了一个 Web 应用程序,它使用 3 足 OAuth 来访问用户的联系人 API。在该过程结束时,我收到一个 access_token 和 access_token_secret,我将它们与 user_id(用户的电子邮件)一起保存在数据库中。
问题是,下次有人尝试通过 OAuth 时,我希望如果我已经有现有 token 来使用它,而不是完成整个过程。
有没有办法在用户进行身份验证之前获取 user_id。
为了进行身份验证,我使用此处的代码: http://code.google.com/appengine/articles/java/retrieving_gdata_feeds.html
最佳答案
在后台使用存储的访问 token 访问页面(\me?access_token=)
。如果 token 仍然有效,您将收到没有错误的响应。如果 token 不再有效,您将收到 OAuthException
作为响应。
get userData with old access token
if exception is thrown => Redo authentication process
else => continue with old token
关于Java OAuth 检索用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9873300/