gpt4 book ai didi

google-people - 从google people api获取用户的电话号码?

转载 作者:行者123 更新时间:2023-12-04 09:44:41 26 4
gpt4 key购买 nike

我可以使用 People API 获取用户的电话号码吗?如果没有,我可以使用其他任何 API 来获取用户的电话号码吗?我似乎找不到任何关于它的东西。

下面的代码是我试过的
首先,我使用 auth2 登录。

useEffect(() => {
console.log("window: ", window);
window.gapi.load("client:auth2", initClient);
}, []);

const initClient = () => {
window.gapi.auth2.init({
client_id: "CLIENT_ID",
});
authenticate().then(loadClient);
};

const authenticate = () => {
return window.gapi.auth2
.getAuthInstance()
.signIn({
scope:
"https://www.googleapis.com/auth/contacts
https://www.googleapis.com/auth/contacts.readonly
https://www.googleapis.com/auth/directory.readonly
https://www.googleapis.com/auth/user.addresses.read
https://www.googleapis.com/auth/user.birthday.read
https://www.googleapis.com/auth/user.emails.read
https://www.googleapis.com/auth/user.gender.read
https://www.googleapis.com/auth/user.organization.read
https://www.googleapis.com/auth/user.phonenumbers.read
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile",
})
.then(
(response) => {
console.log("sign in successful: ", response);
},
(err) => {
console.log("error signing in: ", err);
}
);
};

然后我加载客户端使用。
  const loadClient = () => {
window.gapi.client.setApiKey("API_KEY");
return window.gapi.client
.load("https://people.googleapis.com/$discovery/rest?version=v1")
.then(
() => {
console.log("GAPI client loaded for api");
},
(err) => {
console.log("error loading GAPI client for api: ", err);
}
);
};

最后,我向人们 api 执行此请求以获取信息。
我可以获得登录用户的姓名和电子邮件地址,但我没有获得电话号码。

const execute = () => {
return window.gapi.client.people.people
.get({
resourceName: "people/me",
personFields: "names,emailAddresses,phoneNumbers",
})
.then(
(response) => {
console.log("people response: ", response);
},
(err) => {
console.log("people err: ", err);
}
);
};

最佳答案

您将需要 user.phonenumbers 范围。来自 OAuth 2.0 Scopes section :

查看您/当前用户的电话号码

https://www.googleapis.com/auth/user.phonenumbers.read

然后您可以使用 people.get("people/me")personFields="phoneNumbers"获得 Person实例与 phoneNumbers字段填充。

关于google-people - 从google people api获取用户的电话号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62187972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com