简体   繁体   English

抄写员-使用代码还原访问令牌(OAuth2与OAuth1)

[英]Scribe - restore access token with code (OAuth2 vs OAuth1)

In an OAuth1 process, I save my token and my secret and recreate my access token like the following: 在OAuth1流程中,我保存了令牌和秘密,并重新创建了访问令牌,如下所示:

 accessToken = new Token(token, secret);

In an OAuth2 process, I only get a code. 在OAuth2流程中,我只得到一个代码。 If I save this code and try to recreate the access token like following, the app crashes: 如果我保存此代码并尝试重新创建访问令牌,如下所示,该应用程序将崩溃:

Verifier v = new Verifier(code);
accessToken = service.getAccessToken(null, v);

The response: 响应:

org.scribe.exceptions.OAuthException: Cannot extract an acces token. org.scribe.exceptions.OAuthException:无法提取acces令牌。 Response was: {"code": 400, "error_type": "OAuthException", "error_message": "No matching code found."} 响应为:{“代码”:400,“错误类型”:“ OAuthException”,“错误消息”:“未找到匹配的代码。”}

How do I recreate an access token in an OAuth2 process? 如何在OAuth2流程中重新创建访问令牌?

I think the problem here is not with your Java code to extract the token (the bit that you're showing at least) - that looks fine from what I can tell. 我认为这里的问题不在于您的Java代码提取令牌(至少您正在显示的位)-从我所知道的来看,这看起来不错。

The error message is a response back from the service you're trying to authorize with (eg twitter, or whatever it is in your case) saying that 错误消息是您尝试授权的服务(例如,twitter或您所关注的任何情况)的响应,并指出

code

is not known. 未知。 That could happen if too much time has passed since you got that authorization code from the service, or simply that the authorization code you have is wrong for some reason. 如果自从服务获得授权码以来已经过去了太多时间,或者仅仅是由于某种原因您拥有的授权码是错误的,则可能会发生这种情况。

In order to provide proper answer, I'd need to see a bit more code... how precisely are you getting the value of 为了提供正确的答案,我需要看一些代码...您如何准确地获得...的价值

code

that is going into the constructor of 那将进入

Verifier

? Please can you provide more of the code you're using for that? 请您提供更多您正在使用的代码吗?

[Sorry, I would have added this as a comment, but don't have enough reputation.] [对不起,我会将此添加为评论,但没有足够的声誉。]

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

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