Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

android - Google coordinate authentication

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
    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);
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...