我正在尝试使用 (node.js) 示例应用程序来针对 Google API 进行身份验证,然后发出 Google Drive 请求。我尝试运行的示例来自 googleapis node.js 库的 github 自述文件使用jwt:
var jwtClient = new googleapis.auth.JWT(
'[email protected]',
'./key.pem',
null,
['https://www.googleapis.com/auth/drive'],
'[email protected]');
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% 确定 '[电子邮件受保护]'。使用我的客户端 ID,我收到错误“无效的模拟 prn 电子邮件地址。”。
我已经根据文档创建了服务帐户客户端 ID、服务电子邮件和证书指纹。我必须指定额外的事情吗?我的范围不正确吗?如果是的话,应该是什么?
Google Drive API 在 Google 开发者控制台中启用。我还激活了试用帐户。
呃,在尝试了很多事情之后,结果相当简单:在没有“模拟”电子邮件的情况下执行上述示例,它就成功了。代码:
var jwtClient = new googleapis.auth.JWT(
'[email protected]',
'./key.pem',
null,
['https://www.googleapis.com/auth/drive']);
自述文件中的示例可作为示例中的完整文件使用(here).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)