Google Plus登录问题

时间:2017-05-01 14:42:27

标签: android google-signin googlesigninaccount

Android应用中的

Google+ API签名问题 - 我登录google + api后google登录成功结果

后面的方法获得“NULL”值

代码

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .requestProfile()


        .requestScopes(new Scope(Scopes.PROFILE))
        .build();

mGoogleApiClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this, this)
        .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
        .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
            @Override
            public void onConnected(@Nullable Bundle bundle) {
                googleSignOut();
            }

            @Override
            public void onConnectionSuspended(int i) {

            }
        })
        .build();

结果:

      if (result.isSuccess()) {
    String personName = acct.getDisplayName();
String name=acct.getGivenName();
    }

在上面的结果代码中,都返回空值。

如何获取姓名,名字或姓氏。

1 个答案:

答案 0 :(得分:0)

从google dev控制台创建网络令牌,并在Android应用中使用它。关于这一点,googleblog有很好的指导方针。如果你按照它去,那么我相信,你的问题将得到解决。它发生在我不久前,然后我跟着他们,我的问题解决了。

enter image description here

GoogleSignInOptions gso =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestIdToken(serverClientId) // here you will pass the client server id that you created
    .requestEmail()
    .build();

我希望这会以某种方式帮助你。

相关问题