如何使用react-google-login获取用户的电话号码?



我实际上在使用这个React库(https://www.npmjs.com/package/react-google-login)通过Google进行身份验证
对于基本配置文件和电子邮件范围,这很好。在我在谷歌云平台上的客户端应用程序上,我正确地启用了人民API(https://developers.google.com/people)并在React中将正确的范围添加到范围列表中(https://www.googleapis.com/auth/user.phonenumbers.read)。我还确保我在谷歌个人资料上的电话号码被公开,即使我不知道这是否重要。完成所有这些之后,同意屏幕运行良好,要求我允许应用程序访问我的电话号码

但是登录后,我只能看到链接到配置文件和电子邮件范围的数据。在库中,我可以看到他们在库内部制作了一些对象属性,如下面的代码所示:

function handleSigninSuccess(res) {
/*
offer renamed response keys to names that match use
*/
const basicProfile = res.getBasicProfile()
const authResponse = res.getAuthResponse(true)
res.googleId = basicProfile.getId()
res.tokenObj = authResponse
res.tokenId = authResponse.id_token
res.accessToken = authResponse.access_token
res.profileObj = {
googleId: basicProfile.getId(),
imageUrl: basicProfile.getImageUrl(),
email: basicProfile.getEmail(),
name: basicProfile.getName(),
givenName: basicProfile.getGivenName(),
familyName: basicProfile.getFamilyName()
}
onSuccess(res)
}

\

所以问题是,我不知道我是否收到了电话数据,或者我就是读不懂,因为我不知道如何调用响应中的电话数据,就React中的变量名称而言。有人有主意吗?

您使用的库似乎使用的是Google Identity,它不包括获取用户电话号码的方法,只包括用户的基本配置文件。

您可以使用peopleapi获取用户的电话号码,但这不在这个库的范围内。您必须创建自己的方法来获得带有phoneNumbers字段的经过身份验证的用户配置文件。启用人员api和请求授权只是第一步。

https://developers.google.com/people/api/rest/v1/people/get

相关内容

最新更新