谷歌协调认证 [英] Google coordinate authentication

查看:151
本文介绍了谷歌协调认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试连接到谷歌协调,我总是得到一个异常 GoogleAuthException

我有一个谷歌地图坐标许可证。 我没有创建谷歌控制台我的客户编号与我的包的应用程序的名字和我的SHA1。

我添加的权限,以我的清单文件:

 <使用-权限的Andr​​oid:名称=android.permission.GET_ACCOUNTS/>
<使用-权限的Andr​​oid:名称=android.permission.NETWORK/>
<使用-权限的Andr​​oid:名称=android.permission.USE_CREDENTIALS/>
<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
 

我用这个code:

 最后弦乐SCOPE =oauth2如下:https://www.googleapis.com/auth/coordinate;
尝试 {
    mGoogleCoordinatetoken = GoogleAuthUtil.getToken(活动,电子邮件,SCOPE);
    Log.e(的getClass()getSimpleName()标记=+ mGoogleCoordinatetoken);
}赶上(GooglePlayServicesAvailabilityException playEx){
    Log.e(的getClass()getSimpleName(),GooglePlayServicesAvailabilityException+ playEx.getMessage());
}赶上(UserRecoverableAuthException userAuthEx){
    //利用返回的意图启动用户可恢复操作
    // getIntent()
    Log.e(的getClass()getSimpleName(),UserRecoverableAuthException+ userAuthEx.getMessage());
}赶上(IOException异常transientEx){
    //网络或服务器错误,看涨预期成功,如果您稍后重试。
    //不要试图立即重新调用 - 请求可能
    //失败,你会击中配额或退避。
    Log.e(的getClass()getSimpleName(),IOException异常+ transientEx.getMessage());
}赶上(GoogleAuthException authEx){
    // 失败。呼叫预计不会永远成功,所以它不应该是
    //重试。
    Log.e(的getClass()getSimpleName(),GoogleAuthException+ authEx.getMessage());
}
 

任何想法如何,我可以解决这个例外?

例外:

  01-30 22:24:53.968:E / getAccessToken()(24800):[错误] GoogleAuthException:com.google.android.gms.auth.GoogleAuthException:未知
01-30 22:24:53.998:E / AccessTokenTask(24800):mGoogleCoordinatetoken = NULL
 

解决方案

 字符串WEB_APPLICATION_CLIENT_ID =656631023202-9jsg9faqe87n1uo7f5g6iupti1jl2nps.apps.googleusercontent.com;
    字符串范围=的String.Format(观众:服务器:CLIENT_ID:+ WEB_APPLICATION_CLIENT_ID);

    Log.e(的getClass()getSimpleName(),电子邮件=+电子邮件);

    字符串code = NULL;
    尝试 {
         code = GoogleAuthUtil.getToken(
                 LoginActivity.this,//上下文语境
                 电子邮件,//字符串帐户名
                    领域
                );
         mGoogleCoordinatetoken = code;
    }赶上(IOException异常transientEx){
      //网络或服务器错误,看涨预期成功,如果您稍后重试。
      //不要试图立即重新调用 - 请求可能
      //失败,你会击中配额或退避。
        Log.e(getAccessToken(),[错误] IOException异常:+ transientEx);
    }赶上(UserRecoverableAuthException E){
           // 恢复
        Log.e(getAccessToken(),[错误] UserRecoverableAuthException:+ E);
        code = NULL;
    }赶上(GoogleAuthException authEx){
      // 失败。呼叫预计不会永远成功,所以它不应该是
      //重试。
        Log.e(getAccessToken(),[错误] GoogleAuthException:+ authEx);
    }赶上(例外五){
        Log.e(getAccessToken(),[错误]异常:+ E);
      抛出新的RuntimeException(E);
    }
 

When I try to connect to Google coordinate, I always get an exception GoogleAuthException.

I have a Google Maps Coordinate license. I did create my client Id in google console with my package application name and my SHA1.

I added the permissions to my manifest file:

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.NETWORK"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.INTERNET"/>

I use this code:

final String SCOPE = "oauth2:https://www.googleapis.com/auth/coordinate";
try {
    mGoogleCoordinatetoken = GoogleAuthUtil.getToken(activity, email, SCOPE);
    Log.e(getClass().getSimpleName(), "token ="+mGoogleCoordinatetoken);
} catch (GooglePlayServicesAvailabilityException playEx) {
    Log.e(getClass().getSimpleName(), "GooglePlayServicesAvailabilityException "+playEx.getMessage());
} catch (UserRecoverableAuthException userAuthEx) {
    // Start the user recoverable action using the intent returned by
    // getIntent()
    Log.e(getClass().getSimpleName(), "UserRecoverableAuthException "+userAuthEx.getMessage());
} catch (IOException transientEx) {
    // network or server error, the call is expected to succeed if you try again later.
    // Don't attempt to call again immediately - the request is likely to
    // fail, you'll hit quotas or back-off.
    Log.e(getClass().getSimpleName(), "IOException "+transientEx.getMessage());
} catch (GoogleAuthException authEx) {
    // Failure. The call is not expected to ever succeed so it should not be
    // retried.
    Log.e(getClass().getSimpleName(), "GoogleAuthException "+authEx.getMessage());
}

Any idea how I can fix this exception?

Exception:

01-30 22:24:53.968: E/getAccessToken()(24800): [ERROR] GoogleAuthException: com.google.android.gms.auth.GoogleAuthException: Unknown
01-30 22:24:53.998: E/AccessTokenTask(24800): mGoogleCoordinatetoken =null

解决方案

    String WEB_APPLICATION_CLIENT_ID = "656631023202-9jsg9faqe87n1uo7f5g6iupti1jl2nps.apps.googleusercontent.com";
    String scopes = String.format("audience:server:client_id:" + WEB_APPLICATION_CLIENT_ID );

    Log.e(getClass().getSimpleName(), "email ="+email);

    String code = null;
    try {
         code = GoogleAuthUtil.getToken(
                 LoginActivity.this,                             // Context context
                 email,     // String accountName
                    scopes
                );
         mGoogleCoordinatetoken = code;
    } catch (IOException transientEx) {
      // network or server error, the call is expected to succeed if you try again later.
      // Don't attempt to call again immediately - the request is likely to
      // fail, you'll hit quotas or back-off.
        Log.e("getAccessToken()", "[ERROR] IOException: " + transientEx);
    } catch (UserRecoverableAuthException e) {
           // Recover
        Log.e("getAccessToken()", "[ERROR] UserRecoverableAuthException: " + e);
        code = null;
    } catch (GoogleAuthException authEx) {
      // Failure. The call is not expected to ever succeed so it should not be
      // retried.
        Log.e("getAccessToken()", "[ERROR] GoogleAuthException: " + authEx);
    } catch (Exception e) {
        Log.e("getAccessToken()", "[ERROR] Exception: " + e);
      throw new RuntimeException(e);
    }

这篇关于谷歌协调认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆