在android中使用scribe OAuth时出现无效的验证码格式错误

发布于 2025-01-02 01:18:48 字数 4812 浏览 1 评论 0原文

我正在使用 scribe oAuth 库来实现 Facebook oAuth 登录,使用
这个例子

我已在站点 URL 和移动 Web URL 中设置 www.example.com(有效的 ur) 在 Facebook 应用程序设置中

这是我在 android 中的代码

OAuthService service = new ServiceBuilder()
                                        .provider(FacebookApi.class)
                                        .apiKey(apiKey)
                                        .apiSecret(apiSecret)
                                        .callback("http://www.example.com/")
                                        .build();
          Scanner in = new Scanner(System.in);

          System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
          System.out.println();

          // Obtain the Authorization URL
          System.out.println("Fetching the Authorization URL...");
          String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
          System.out.println("Got the Authorization URL!");
          System.out.println("Now go and authorize Scribe here:");
          System.out.println(authorizationUrl);
          System.out.println("And paste the authorization code here");
          System.out.print(">>");
          String val = new String();
          if(in.hasNextLine())
           val = in.nextLine();
          System.out.println("VALUE"+val);
          Verifier verifier = new Verifier(val);
          System.out.println();

          // Trade the Request Token and Verfier for the Access Token
          System.out.println("Trading the Request Token for an Access Token...");
          Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
          System.out.println("Got the Access Token!");
          System.out.println("(if your curious it looks like this: " + accessToken + " )");
          System.out.println();

但我收到以下错误

Caused by: org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract a token from this: '{"error":{"message":"Invalid verification code format.","type":"OAuthException"}}'

Logcat

: === Facebook's OAuth Workflow === : Fetching the Authorization URL... : Got the Authorization URL! : Now go and authorize Scribe here: : https://www.facebook.com/dialog/oauth?client_id=XXXXXXXXXXXX&redirect_uri=http%3A%2F%2Fwww.example.com%2F : And paste the authorization code here : >>VALUE  Trading the Request Token for an Access Token... GC_FOR_MALLOC freed 5523 objects / 320760 bytes in 81ms AndroidRuntime(541): Shutting down VM : threadid=1: thread exiting with uncaught exception (group=0x4001d800)  FATAL EXCEPTION: main  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.commauth/com.commauth.CommonAuthActivity}: org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract a token from this: '{"error":{"message":"Invalid verification code format.","type":"OAuthException"}}'
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:123)
     at android.app.ActivityThread.main(ActivityThread.java:4627)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:521)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
     at dalvik.system.NativeStart.main(Native Method)  Caused by: org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract a token from this: '{"error":{"message":"Invalid verification code format.","type":"OAuthException"}}'
     at org.scribe.extractors.TokenExtractor20Impl.extract(TokenExtractor20Impl.java:33)
     at org.scribe.oauth.OAuth20ServiceImpl.getAccessToken(OAuth20ServiceImpl.java:37)
     at com.commauth.CommonAuthActivity.onCreate(CommonAuthActivity.java:57)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
     ... 11 more

如果我将其作为独立程序运行,那么它会要求我提供一些授权代码 但我真的不知道该放什么进去。

在代码行这里

Scanner in = new Scanner(System.in);
Verifier verifier = new Verifier(in.nextLine());
System.out.println();

i am using scribe oAuth library to implement Facebook oAuth login , using
this example

I have set www.example.com (a valid ur) in Site URL and Mobile Web Url
in facebook application setting

here is my code in android

OAuthService service = new ServiceBuilder()
                                        .provider(FacebookApi.class)
                                        .apiKey(apiKey)
                                        .apiSecret(apiSecret)
                                        .callback("http://www.example.com/")
                                        .build();
          Scanner in = new Scanner(System.in);

          System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
          System.out.println();

          // Obtain the Authorization URL
          System.out.println("Fetching the Authorization URL...");
          String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
          System.out.println("Got the Authorization URL!");
          System.out.println("Now go and authorize Scribe here:");
          System.out.println(authorizationUrl);
          System.out.println("And paste the authorization code here");
          System.out.print(">>");
          String val = new String();
          if(in.hasNextLine())
           val = in.nextLine();
          System.out.println("VALUE"+val);
          Verifier verifier = new Verifier(val);
          System.out.println();

          // Trade the Request Token and Verfier for the Access Token
          System.out.println("Trading the Request Token for an Access Token...");
          Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
          System.out.println("Got the Access Token!");
          System.out.println("(if your curious it looks like this: " + accessToken + " )");
          System.out.println();

but i am getting following error

Caused by: org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract a token from this: '{"error":{"message":"Invalid verification code format.","type":"OAuthException"}}'

Logcat

: === Facebook's OAuth Workflow === : Fetching the Authorization URL... : Got the Authorization URL! : Now go and authorize Scribe here: : https://www.facebook.com/dialog/oauth?client_id=XXXXXXXXXXXX&redirect_uri=http%3A%2F%2Fwww.example.com%2F : And paste the authorization code here : >>VALUE  Trading the Request Token for an Access Token... GC_FOR_MALLOC freed 5523 objects / 320760 bytes in 81ms AndroidRuntime(541): Shutting down VM : threadid=1: thread exiting with uncaught exception (group=0x4001d800)  FATAL EXCEPTION: main  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.commauth/com.commauth.CommonAuthActivity}: org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract a token from this: '{"error":{"message":"Invalid verification code format.","type":"OAuthException"}}'
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:123)
     at android.app.ActivityThread.main(ActivityThread.java:4627)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:521)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
     at dalvik.system.NativeStart.main(Native Method)  Caused by: org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract a token from this: '{"error":{"message":"Invalid verification code format.","type":"OAuthException"}}'
     at org.scribe.extractors.TokenExtractor20Impl.extract(TokenExtractor20Impl.java:33)
     at org.scribe.oauth.OAuth20ServiceImpl.getAccessToken(OAuth20ServiceImpl.java:37)
     at com.commauth.CommonAuthActivity.onCreate(CommonAuthActivity.java:57)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
     ... 11 more

IF i run this as a standalone program then it asks me for some authorization code
but i really don't know wht to put in there.

here at the code line

Scanner in = new Scanner(System.in);
Verifier verifier = new Verifier(in.nextLine());
System.out.println();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

这个俗人 2025-01-09 01:18:48

尝试在回调网址末尾添加斜杠。我花了几个小时解决这个问题!感谢这篇文章 我找到了答案!

Try adding a slash at the end of your callback url. I spent a few HOURS troubleshooting this!!! Thanks to this post I found the answer!

甜中书 2025-01-09 01:18:48

我遇到了同样的问题,事实上,我只是发现我输入的代码不正确。当我从导航器地址复制它时,它没有复制整个代码(太大?)。因此请仔细检查代码是否正确。

I had the same issue, and in fact, I just see that the code that I was entering was not correct. When I was copiyng it from the navigator address, it didn't copy the whole code (too big ?). So double check if the code is the good one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文