Android - how to get google plus access token?

前端 未结 2 446
有刺的猬
有刺的猬 2020-12-09 12:40

Hello i am getting google plus access token without using OAuth 2.0 client ID with scopes. But with this access token does not fetch email address. How to fetch user email

2条回答
  •  不思量自难忘°
    2020-12-09 12:47

    String accessToken = "";
    try {
      URL url = new URL("https://www.googleapis.com/oauth2/v1/userinfo");
      // get Access Token with Scopes.PLUS_PROFILE
      String sAccessToken;
      sAccessToken = GoogleAuthUtil.getToken(
        LoginCheckActivity.this,
        mPlusClient.getAccountName() + "",
        "oauth2:"
          + Scopes.PLUS_PROFILE + " "
          + "https://www.googleapis.com/auth/plus.login" + " "
          + "https://www.googleapis.com/auth/plus.profile.emails.read");
    } catch (UserRecoverableAuthException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();                  
      Intent recover = e.getIntent();
      startActivityForResult(recover, 125);
      return "";
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (GoogleAuthException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    

提交回复
热议问题