当我调用任何Google API时,出现此错误“请求的身份验证范围不足

时间:2019-07-18 14:01:29

标签: authentication google-api-nodejs-client

我正在通过android管理API创建企业ID。因此,我必须先创建一个注册URL。向Google发布请求时,它将提供"Request had insufficient authentication scopes." ERROR

我在nodejs中使用googleapis模块

const _access_token = await googleUtils.getAccessToken();    

if (_access_token){

  const defaultScope = [
    'https://www.googleapis.com/auth/plus.me',
    'https://www.googleapis.com/auth/userinfo.email'
  ];

  var postData = querystring.stringify({
    'callbackUrl' : 'https://localhost:300/settings/getsettings',
    'projectId'   : 'studious-rhythm-246118'       
  });

  var options = {
    hostname: 'androidmanagement.googleapis.com',
    port: 443,
    path: '/v1/signupUrls',
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded',
        //'Content-Length': postData.length,
        'Authorization':  'Bearer '+_access_token                        
      }
  };

console.log(options);  
var req = https.request(options, (resp) => {    
  resp.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (e) => {
  console.error(e);
});
req.write(postData);
req.end();

0 个答案:

没有答案