gpt4 book ai didi

node.js - 使用服务帐户的 Google 身份验证失败 (node.js)

转载 作者:搜寻专家 更新时间:2023-10-31 22:56:47 24 4
gpt4 key购买 nike

我正在尝试使用 (node.js) 示例应用程序对 Google API 进行身份验证,然后发出 Google Drive 请求。我尝试运行的示例来自 googleapis node.js 库的 github 自述文件 using jwt :

var jwtClient = new googleapis.auth.JWT(
'123...xyz@developer.gserviceaccount.com',
'./key.pem',
null,
['https://www.googleapis.com/auth/drive'],
'my.personal@gmail.com');

jwtClient.authorize(function(err, tokens) {
if (err) {
console.log(err);
return;
}

// Make an authorized request to list Drive files.
drive.files.list({ auth: jwtClient }, function(err, resp) {
// handle err and response
});
});

身份验证失败:

{ error: 'unauthorized_client',
error_description: 'Unauthorized client or scope in request.' }

我不是 100% 确定“my.personal@gmail.com”。使用我的客户端 ID,我收到错误“无效的模拟 prn 电子邮件地址”。

我已根据文档创建了服务帐户客户端 ID、服务电子邮件和证书指纹。我必须指定额外的东西吗?我的范围不正确吗?如果是,它应该是什么?

Google Drive API 已在 Google Developer Console 中启用。我还激活了试用帐户。

最佳答案

呃,在尝试了很多事情之后,结果相当简单:在没有“模拟”-email 的情况下执行上面的示例它就成功了。代码:

var jwtClient = new googleapis.auth.JWT(
'123...xyz@developer.gserviceaccount.com',
'./key.pem',
null,
['https://www.googleapis.com/auth/drive']);

自述文件中的示例在示例 ( here ) 中作为完整文件提供。

关于node.js - 使用服务帐户的 Google 身份验证失败 (node.js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27956244/

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