【问题标题】:GoogleApiClient - Connected / Selected User AccountGoogleApiClient - 连接/选定的用户帐户
【发布时间】:2016-07-05 14:04:25
【问题描述】:

如何从 GoogleApiClient 获取实际连接/选定的用户?

我使用这个代码:

mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();

用户从弹出窗口中选择帐户并调用“onConnected”,但我没有得到选择的帐户。

我想显示这个信息,那么我怎样才能得到这个信息呢?

【问题讨论】:

    标签: android google-drive-api google-api-client google-drive-android-api


    【解决方案1】:
          private void getProfileInformation() {
               try {
              if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
                Person currentPerson = Plus.PeopleApi
                        .getCurrentPerson(mGoogleApiClient);
                String personName = currentPerson.getDisplayName();
                String personPhotoUrl = currentPerson.getImage().getUrl();
                String personGooglePlusProfile = currentPerson.getUrl();
                String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
    
              }
    
        catch(Exception e){}
    
    
      }
    
        }
    

    OnConnected 调用 getProfileInformation 方法

      @Override
       public void onConnected(Bundle arg0) {
        mSignInClicked = false;
        Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
    
        // Get user's information
        getProfileInformation();
    
    
    
    }
    

    【讨论】:

    • 是的,我见过这种方法,但我真的需要 PLUS PeopleApi 来获取这些信息吗?这有点开销......用户已经选择了它,非常奇怪,我没有直接从 googleApiClient 获取它。
    • 是的,您需要调用 Plus Api 来获取所有这些信息
    • 很奇怪。好的,但不推荐使用 getCurrentPerson。
    • 我让用户在应用程序中选择用户的帐户,然后使用该帐户进行登录
    • 如果用户没有 Plus 帐户怎么办?我只需要 Drive API 帐户选择器中所选用户的邮件地址...
    猜你喜欢
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 2019-04-13
    相关资源
    最近更新 更多