有一种在App Engine端设置oauth的内置方法,它适用于来自我的本地计算机的请求,其中包含由GoogleCredentials生成的令牌。get_application_default(),但它没有适用于计算引擎的请求,App Engine端有NotAllowedError
例外。
我多次尝试配置请求范围以包含https://www.googleapis.com/auth/userinfo.emails
作为必需范围,但没有运气。
答案 0 :(得分:4)
事实证明,当您使用Allow API access to all Google Cloud services in the same project.
创建实例时,不包含所需的用户信息范围。
要包含用户信息范围,您必须取消选中Allow API access to all Google Cloud services in the same project.
,转到Access & Security
标签并明确启用用户信息范围。
更新2018-11-15
现在设置电子邮件范围的正确方法是使用gcloud命令:
gcloud compute instances set-service-account INSTANCE-ID --zone=us-central1-f --service-account=PROJECT-ID-compute@developer.gserviceaccount.com --scopes https://www.googleapis.com/auth/userinfo.email,cloud-platform