Google coordinate authentication

前端 未结 3 814
再見小時候
再見小時候 2020-12-01 15:40

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 clie

相关标签:
3条回答
  • 2020-12-01 16:04

    I had the exact same problem and resolved by modifying the scope to :

    "oauth2:https://www.googleapis.com/auth/[API YOU WANT]"
    

    (the beggining is very important !)

    Hope it will help someone :)

    0 讨论(0)
  • 2020-12-01 16:06

    The question is why do you need to get a token. As you commented in my question, you should be fine with GoogleAccountCredential object. Once you have the credential object, you can make calls to Google APIs

      credential = GoogleAccountCredential.usingOAuth2(this, scopes);
                    if (TextUtils.isEmpty(appPreferences.getUserName()))
                    {
                            try
                            {
    
                                    startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
                            }
                            catch (ActivityNotFoundException e)
                            {
    
                                    Toast.makeText(this, getString(R.string.gps_missing), Toast.LENGTH_LONG).show();
    
                                    return;
                            }
    
                    }
    
    0 讨论(0)
  • 2020-12-01 16:15
        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);
        }
    
    0 讨论(0)
提交回复
热议问题