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

tok*_*osh 4 google-api node.js jwt

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

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
  });
});
Run Code Online (Sandbox Code Playgroud)

身份验证失败:

{ error: 'unauthorized_client',
  error_description: 'Unauthorized client or scope in request.' }
Run Code Online (Sandbox Code Playgroud)

我对'my.personal@gmail.com'并不是100%肯定.使用我的客户端ID,我收到错误"无效模仿prn电子邮件地址.".

我根据文档创建了服务帐户客户端ID,服务电子邮件和证书指纹.我是否必须指定其他内容?我的范围不正确吗?如果是的话,应该是什么?

Google云端硬盘控制台已在Google Developer Console中启用.我还激活了试用帐户.

tok*_*osh 13

呃,在尝试了很多东西之后,结果很简单:在没有"模仿"的情况下做上面的例子 - 电子邮件就可以了.码:

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

自述文件中的示例在示例(此处)中作为完整文件提供.