我仍然收到错误403 - Not Authorized to access this resource/api
接下来我应该测试或检查什么?
const fs = require('fs');
const { google } = require('googleapis');
const privatekey = require('./keyfile.json');
// configure a JWT auth client
let jwtClient = new google.auth.JWT(
privatekey.client_id,
null,
privatekey.private_key,
['https://www.googleapis.com/auth/admin.directory.user.readonly']);
// authenticate request
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
} else {
console.log("Successfully connected!");
authCallback(jwtClient);
}
});
function authCallback(auth) {
const service = google.admin('directory_v1');
let a = service.users.get({
'auth': auth,
'userKey': 'user@domain.org',
'viewType': 'domain_public'
}, function(err, data) {
// Shows the error here
console.log(err || data);
});
}