【问题标题】:Can't get user birthday with Google Play services API无法使用 Google Play 服务 API 获取用户生日
【发布时间】:2016-04-08 08:46:57
【问题描述】:

编辑

经过新的尝试,我终于迎来了我的生日。我没有改变实现。我想我的 Google Plus 个人资料中的更改需要几个小时才能传播,从而公开我的生日。有点超出预期。现在我想知道是否可以在用户登录时询问此权限(生日),而无需公开生日。

正如developers guide 中的此信息所建议的那样:

有关可能可用的其他个人资料数据,请参阅 谷歌登录帐户。请注意,任何配置文件字段都可以为空, 取决于您要求的范围和信息 用户的个人资料包括。

初始 POST

我想在用户登录 Google Plus 后获取他的生日。由于一般不熟悉 Google API,我想知道我的实现是否有意义。现在,我只是想通过与我的设备关联的 Google 帐户来获取自己的生日。

这就是我所做的。我按照developer guide 的步骤进行了登录过程。除了 OAuth,我还在 gradle 中添加了 Google Plus 依赖:

编译'com.google.android.gms:play-services-plus:8.3.0'

在我的Activity 中,有一个用于登录 Google Plus 的按钮。

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PLUS_ME), new Scope(Scopes.PLUS_LOGIN),new Scope(Scopes.PROFILE))
                .build();
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API)
                .build();


loginButton = (SignInButton) findViewById(R.id.sign_in_button);
loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
                startActivityForResult(signInIntent, RC_SIGN_IN);
            }
        });

初次登录后,我尝试连接到 Google Play 服务。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            Log.d(TAG, "handleSignInResult:" + result.isSuccess());
            if (result.isSuccess()) {
                mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
           }
    }
}

连接后,我会尝试获取用户的生日。

@Override
    public void onConnected(Bundle bundle) {
        Person currentPerson = Plus.PeopleApi
                .getCurrentPerson(mGoogleApiClient);
        addGoogleProfile(currentPerson); //Add the user to a list of persons
        refreshListView(); //update the listView
        Log.d(TAG, "Current person: name=" + currentPerson.getDisplayName() + ", has birthday = " + (currentPerson.hasBirthday() ? "yes, it is" + currentPerson.getBirthday() : "no"));
    }

问题

生日永远不会设置并且总是显示为空。可以访问其他数据,例如姓名和个人资料图像。我没有找到关于不同Scopes 的太多信息。我更熟悉 Facebook API,在登录时更明确地请求权限。

知道我缺少什么吗?

何和我将我的生日字段设置为关联 Google 帐户的“公开”。

干杯

【问题讨论】:

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


【解决方案1】:

亲爱的你只能得到以下信息:-

mePerson.getId()
mePerson.getDisplayName()
mePerson.getImage().getUrl()
mePerson.getUrl()

【讨论】:

【解决方案2】:

我们可以从 gmail 获取用户的生日,但为此用户需要公开查看生日。

按照以下步骤操作:

  1. 登录 gmail 并转到:https://myaccount.google.com/u/1/birthday?hl=en&pli=1
  2. 点击“管理分享设置”,将生日设为公开
  3. 添加范围:https://www.googleapis.com/auth/plus.login

【讨论】:

    猜你喜欢
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    相关资源
    最近更新 更多