对社交api身份验证进行故障排除

时间:2012-11-26 20:31:41

标签: java scribe

我刚刚开始使用twitter / facebook等社交网络查看scribe进行身份验证。我使用twitter的示例作为参考。但是,由于某种原因,我似乎没有从twitter获得oauth_verifier(即使回调是通过服务构建器注册的 - 我在回调中使用localhost,因为它与另一个社交api一起工作)。任何有用的建议都会非常受欢迎。提前谢谢。

OAuthService service = new ServiceBuilder()
.provider(TwitterApi.class)
.apiKey(consumerKey)
.apiSecret(consumerSecret)
.callback("http://localhost/oauth/twitter")
.build();

        //get the token
        Token requestToken = service.getRequestToken();

        String authUrl = service.getAuthorizationUrl(requestToken);
        Logger.info("authurl::" + authUrl); // not getting the oauth_verifier

来自scribe的调试输出我更改了令牌信息):

setting oauth_callback to http://localhost/oauth/twitter
generating signature...
base string is: POST&http%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Flocalhost%252Foauth%252Ftwitter%26oauth_consumer_key%3DAAACCCV6ASDFGHJCgYBCD%26oauth_nonce%3D607134093%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1353965859%26oauth_version%3D1.0
signature is: +mSqKJIC1Q0pMEFs/gIJViF7kbg=
appended additional OAuth parameters: { oauth_callback -> http://localhost/oauth/twitter , oauth_signature -> +mSqKJIC1Q0pMEFs/gIJViF7kbg= , oauth_version -> 1.0 , oauth_nonce -> 607134093 , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> AAACCCV6ASDFGHJCgYBCD , oauth_timestamp -> 1353965859 }
using Http Header signature
sending request...
response status code: 200
response body: oauth_token=itJrpOP3KLeD7Ha6oy0IRr4HysFut5eAOpIlj8OmNE&oauth_token_secret=X8LmhAUpvIkfEd7t7P1lvwwobC3JJIhUabcEs0Rn5w&oauth_callback_confirmed=true
authurl::https://api.twitter.com/oauth/authorize?oauth_token=itJrpOP3KLeD7Ha6oy0IRr4HysFut5eAOpIlj8OmNE
obtaining access token from http://api.twitter.com/oauth/access_token
setting token to: Token[itJrpOP3KLeD7Ha6oy0IRr4HysFut5eAOpIlj8OmNE , X8LmhAUpvIkfEd7t7P1lvwwobC3JJIhUabcEs0Rn5w] and verifier to: org.scribe.model.Verifier@55ac8c3d
generating signature...

更新: 我现在能够收到oauth_verifier。一旦我完成测试,我会更新这篇文章。

1 个答案:

答案 0 :(得分:1)

导航错误大多数。我能够使用scribe让oauth与twitter合作。获得服务后,来自服务和服务的请求令牌然后来自服务的authorizationUrl(在传递请求令牌时),我能够重定向到授权URL。在那里,我能够使用我的Twitter ID对Twitter进行身份验证,并将我重定向到创建服务时指定的回调URL。在验证后,我收到了oauth_verifier,我可以用它来创建验证器&然后使用验证程序和请求令牌从服务接收访问令牌。然后提出了oauth请求&签名导致twitter的回复与用户详细信息。工作。希望它有所帮助。