我无法从回复中获取电子邮件 ID 回复如下:
{
"id": "00000000000000",
"name": "Fred Example",
"given_name": "Fred",
"family_name": "Example",
"picture": "https://lh5.googleusercontent.com/-2Sv-4bBMLLA/AAAAAAAAAAI/AAAAAAAAABo/bEG4kI2mG0I/photo.jpg",
"locale": "en"
}
这就是我正在使用的:
https://www.googleapis.com/oauth2/v1/userinfo?access_token=' + token
您可能需要不同的范围。根据文档,范围
https://www.googleapis.com/auth/userinfo.profile
允许您查看基本的个人资料信息。为了查看电子邮件,您需要此范围:https://www.googleapis.com/auth/userinfo.email
。
现在我可以收到回复电子邮件了,下面是代码,我在其中更改了清单中的响应
"oauth2": {
"client_id": "854569859639-9c0reicivklkv0ltpakv99iajqts5obs.apps.googleusercontent.com",
"scopes": [ "https://www.googleapis.com/auth/userinfo.email" ]}
我将范围
"scopes": [ "https://www.googleapis.com/auth/plus.login" ]
更改为 "scopes": [ "https://www.googleapis.com/auth/userinfo.email" ]
以下是回复
"{
"id": "00000000000000",
"name": "Fred Example",
"email":"[email protected]",
"given_name": "Fred",
"family_name": "Example",
"picture": "https://lh5.googleusercontent.com/-2Sv-4bBMLLA/AAAAAAAAAAI/AAAAAAAAABo/bEG4kI2mG0I/photo.jpg",
"locale": "en"
}"
它说:
从源“https://www.prokademi.com”访问“https://www.googleapis.com/auth/userinfo.email”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。