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

标签 android facebook oauth-2.0 scribe

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

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

这是我在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"}}'

逻辑猫

: === 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();

最佳答案

尝试在回调 url 的末尾添加斜线。我花了几个小时解决这个问题!!!感谢this post我找到了答案!

关于android - 在android中使用scribe OAuth时出现无效的验证码格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9124492/

相关文章:

android - 如何使用事件 URI 以编程方式向日历事件添加提醒?

android - 在时间戳 Firebase 上建立索引

java - 查询 ContentProvider 时出现 "Invalid Tables"错误

android - 如何在 flutter 中将 DateTime 转换为 TZDateTime?

python - 使用 Selenium 进行 Facebook 搜索

dependency-injection - 在 Google Cloud Endpoints 上的自定义身份验证器中使用 Guice 注入(inject)

android - 获取 Facebook 个人资料图片时 Bitmap 为 null

java - 从 Facebook Graph 响应中解析 java 中的 JSON 数据

oauth-2.0 - 发送带有对象标签的 http 请求 header

python - 如何使用客户端 ID 和 key 将 OAuth 实现到 FastAPI