【问题标题】:google play services 8.3.0 - get g+ cover image ( deprecated Plus.PeopleApi.getCurrentPerson() )google play services 8.3.0 - 获取 g+ 封面图片(已弃用 Plus.PeopleApi.getCurrentPerson() )
【发布时间】:2016-02-17 20:31:15
【问题描述】:

使用 google play services 登录 g+ 后如何获取封面图片?

使用以前的播放服务版本 Plus.PeopleApi.getCurrentPerson().getCover() 工作正常,但现在此方法已弃用,Plus.PeopleApi.getCurrentPerson() 返回 null。我请求配置文件范围和Plus.API

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestProfile()
        //.requestIdToken()
        .requestEmail()
        .requestScopes(Plus.SCOPE_PLUS_LOGIN, Plus.SCOPE_PLUS_PROFILE, new Scope("https://www.googleapis.com/auth/plus.profile.emails.read"))
        .build();
// [END configure_signin]

// [START build_client]
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
        .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
        .addApi(Plus.API)
        .build();

谢谢!

【问题讨论】:

    标签: android google-play-services google-signin


    【解决方案1】:

    您是否添加了 OAuth 密钥?同时创建 OAuth 常量屏幕。我添加这个后才得到结果

    【讨论】:

      【解决方案2】:

      您好,我找到了最新 google plus 登录使用的方法以下方法:-

        GoogleApiClient mGoogleApiClient;
      
      private void latestGooglePlus() {
          GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                  .requestProfile().requestEmail().requestScopes(Plus.SCOPE_PLUS_LOGIN, Plus.SCOPE_PLUS_PROFILE, new Scope("https://www.googleapis.com/auth/plus.profile.emails.read"))
                  .build();
      
          mGoogleApiClient = new GoogleApiClient.Builder(this)
                  .enableAutoManage(this, this)
                  .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                  .addApi(Plus.API)
                  .build();
      
      
          Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
          startActivityForResult(signInIntent, YOURREQUESTCODE);
      }
      

      活动结果上使用以下代码:-

         @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          Log.e("Activity Res", "" + requestCode);
          if (requestCode == YOURREQUESTCODE) {
      
              GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
              if (result.isSuccess()) {
                   GoogleSignInAccount acct = result.getSignInAccount();
                  acct.getPhotoUrl();
                  acct.getId();
                  Log.e(TAG, acct.getDisplayName());
                  Log.e(TAG, acct.getEmail());
      
      
                  Plus.PeopleApi.load(mGoogleApiClient, "signed_in_user_account_id").setResultCallback(new ResultCallback<People.LoadPeopleResult>() {
                      @Override
                      public void onResult(@NonNull People.LoadPeopleResult loadPeopleResult) {
                           PersonBuffer personBuffer = loadPeopleResult.getPersonBuffer();
                          if (personBuffer != null && personBuffer.getCount() > 0) {
                              Person currentUser = personBuffer.get(0);
                              personBuffer.release();
                              Person.Cover cover = currentUser.getCover();
                              if (cover != null) {
                                  Person.Cover.CoverPhoto coverPhoto = cover.getCoverPhoto();
                                  if (coverPhoto != null) {
                                      String userCoverPhotoUrl = coverPhoto.getUrl();
                                      Log.i("Main TAG", "Cover photo Url :" + userCoverPhotoUrl);
      
                                  }
                              } else {
                                  Log.i("TAG NO COVER", "Person has no cover");
                              }
                          }
                  });
              }
      
      
          }  
      }
      

      最后你的 onclick 将是:-

       @Override
      public void onClick(View v) {
          switch (v.getId()) {
      
      
              case R.id.txtGooglePlus:
                  latestGooglePlus();
                  break;
      
              default:
                  break;
      
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-21
        • 1970-01-01
        • 1970-01-01
        • 2016-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多