适用于Admin SDK Directory API的Google-apis-nodejs-client JWT身份验证

时间:2018-10-12 12:36:06

标签: google-api-nodejs-client

我使用了以下代码段:

let {google} = require('googleapis');
let privatekey = require("./privatekey.json");

    // configure a JWT auth client
    let jwtClient = new google.auth.JWT(
           privatekey.client_email,
           null,
           privatekey.private_key,
           [
             'https://www.googleapis.com/auth/admin.directory.user', 
             'https://www.googleapis.com/auth/admin.directory.user.readonly',
             'https://www.googleapis.com/auth/admin.directory.group', 
             //'https://www.googleapis.com/auth/plus.business.manage'
           ],

          'mybusinessacc.com'
    );
    //authenticate request
    jwtClient.authorize(function (err, tokens) {
     if (err) {
       console.log(err);
       return;
     } else {

       console.log("Successfully connected!");
     }
    });

哪个连接成功,但是当我按此说明访问任何目录API时http://googleapis.github.io/google-api-nodejs-client/modules/_apis_admin_directory_v1_.html 我收到此错误:API返回错误:需要登录

0 个答案:

没有答案