我通过将GOOGLE_APPLICATION_CREDENTIALS
环境变量设置为我的App Engine服务帐户(例如example@appspot.gserviceaccount.com
)的密钥的路径来进行身份验证。
如果日历直接共享到App Engine服务帐户,我可以这样做:
let googleCalendar = google.calendar({
version: 'v3',
auth: new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/calendar'],
})
});
但我希望用户与我拥有的另一个服务帐户google-calendar@example.iam.gserviceaccount.com
共享他们的日历。因此,我希望App Engine服务帐户模拟google-calendar
帐户。我尝试过这个(以及其他一些次要的变化):
let googleCalendar = google.calendar({
version: 'v3',
auth: new google.auth.GoogleAuth({
clientOptions: {
subject: 'google-calendar@uniserval-app.iam.gserviceaccount.com'
},
scopes: ['https://www.googleapis.com/auth/calendar'],
})
});
我得到一个401错误:Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.
我尝试使我的App Engine服务帐户成为google-calendar
服务帐户的成员,并授予它各种角色,如Service Account User
和Service Account Token Creator
-但没有任何变化。
我怀疑代码是正确的,我只是没有配置正确的角色...但在这一点上,我已经搜索了两天的时间,我找不到任何关于如何做到这一点的文档。
发布于 2020-10-07 02:34:52
您的语法看起来是正确的,只是您似乎误解了将哪个电子邮件地址设置为主题。主题是您希望代表其执行操作的用户帐户。
new google.auth.GoogleAuth({
clientOptions: {
subject: 'someone@yourdomain.com'
},
scopes: ['https://www.googleapis.com/auth/calendar'],
})
https://stackoverflow.com/questions/60246245
复制相似问题