【问题标题】:Getting Error: unauthorized_client when trying to authorize script尝试授权脚本时出现错误:未授权客户端
【发布时间】:2017-01-19 07:58:58
【问题描述】:

我已经创建了具有域范围委派及其范围(在管理控制台和开发者控制台中)的服务帐户,如文档中所述。我已经尝试了一个星期,但我被卡住了。这是我的代码:

const google = require('googleapis');
const gmail = google.gmail('v1');
const directory = google.admin('directory_v1');
const scopes = [
  'https://www.googleapis.com/auth/gmail.readonly',
  'https://www.googleapis.com/auth/admin.directory.user.readonly'
];
const key = require('./service_key.json');

var authClient = new google.auth.JWT(
  key.client_email,
  key,
  key.private_key,
  scopes,
  "kruno@example.com"
);

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

// API call methods here...

});

我得到这个错误:

错误:未授权客户端

我无法理解:

  • 在没有任何用户交互的情况下,从服务器端脚本调用 Google API 方法是否合适? (仅限域下)
  • 服务帐户和实际用户帐户如何以这种方式通信?
  • 我听说了回调 URI,我错过了吗?

【问题讨论】:

    标签: node.js google-api authorization jwt google-api-nodejs-client


    【解决方案1】:

    我认为您错过了最后一步,即在您的域的控制面板中访问您的应用程序。

    您可以按照 doc 正确使用您的应用程序来激活它

    https://developers.google.com/+/domains/authentication/delegation

    您也可以从这里开始您的第一个调用步骤

    https://developers.google.com/adwords/api/docs/guides/first-api-call

    【讨论】:

    • 我已经为此服务帐户授予了域范围的权限和范围。我不明白我到底错过了哪一部分?
    • 你是怎么解决这个@Kunok的?
    • @tiagoperes 在我的情况下,范围没有正确匹配。你能描述一下你的问题吗?
    • 我遇到的问题是争论不正确。已经修好了,谢谢我现在的问题是 ''WSGIRequest' 对象没有属性 'Reddit' '
    • 只是让你知道,这个问题也得到了解决。如果您偶然发现并且不知道自己做错了什么,请查看我的个人资料
    猜你喜欢
    • 2020-03-27
    • 2017-02-22
    • 2020-12-31
    • 2019-10-30
    • 2016-06-29
    • 2013-08-03
    • 2018-10-20
    • 2018-07-07
    • 1970-01-01
    相关资源
    最近更新 更多