相关疑难解决方法(0)

如何在Android中使用Google登录获取性别等个人资料?

我想将谷歌登录集成到我的应用程序,当用户首次登录我将创建一个帐户绑定到此,所以我需要一些配置文件,如性别,区域设置等,我尝试作为谷歌登录文档和快速-start示例显示:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
Run Code Online (Sandbox Code Playgroud)

点击登录时我会打电话:

  Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);
Run Code Online (Sandbox Code Playgroud)

登录成功后,我可以在onActivityResult中获取数据结构GoogleSignInResult,来自GoogleSignInResult我可以获得一个GoogleSignInAccount,其中只包含DisplayName,email和id.但是在https://developers.google.com/apis-explorer/#p/中,我可以获得性别,语言环境等个人资料.我错过了什么吗?

我试过google plus api,似乎我可以得到我想要的东西.但是不知道如何使用,doc说创建客户端是这样的:

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(new Scope(Scopes.PLUS_LOGIN))
            .addScope(new Scope(Scopes.PLUS_ME))
            .build();
Run Code Online (Sandbox Code Playgroud)

但是当我使用它时,单击登录按钮将导致应用程序崩溃.

更新: 更新到新版Google的问题登录使用Google Services 3.0.0时丢失api_key /当前密钥

android google-plus-signin google-signin

25
推荐指数
2
解决办法
2万
查看次数