Google api Google Cloud Search通过Node.js查询错误:此项目未启用Cloud Search的查询API

Google api Google Cloud Search通过Node.js查询错误:此项目未启用Cloud Search的查询API,google-api,google-api-nodejs-client,google-cloud-search,Google Api,Google Api Nodejs Client,Google Cloud Search,我正在开发谷歌云搜索API来搜索存储在谷歌硬盘中的文档。我有谷歌工作区帐户和谷歌驱动器中存储的几个文档。我可以使用Google云搜索控制台进行搜索,但在使用下面的node.js代码进行API搜索时遇到了问题 问题:我能够生成访问令牌,但在搜索查询时出现以下错误: 错误:此项目未启用云搜索的查询API, 和/或云搜索平台许可证尚未分配给 调用查询API的用户帐户 在上面的代码中,我将工作区管理员的电子邮件id作为主题传递 我遵循下面链接中提到的步骤 var {google} = require(&

我正在开发谷歌云搜索API来搜索存储在谷歌硬盘中的文档。我有谷歌工作区帐户和谷歌驱动器中存储的几个文档。我可以使用Google云搜索控制台进行搜索,但在使用下面的node.js代码进行API搜索时遇到了问题

问题:我能够生成访问令牌,但在搜索查询时出现以下错误:

错误:此项目未启用云搜索的查询API, 和/或云搜索平台许可证尚未分配给 调用查询API的用户帐户

在上面的代码中,我将工作区管理员的电子邮件id作为主题传递

我遵循下面链接中提到的步骤

var {google} = require("googleapis");

var serviceAccount  = require('C:/nodejstest/key/serviceAccountKey.json');

// Specify the required scope.
var scopes = [
    "https://www.googleapis.com/auth/cloud_search",
    "https://www.googleapis.com/auth/cloud_search.query"
  ];

var jwtClient = new google.auth.JWT({
  email: serviceAccount.client_email,
  key: serviceAccount.private_key,
  scopes: scopes,
  subject: 'sample@example.com'
});

// Use the JWT client to generate an access token.
jwtClient.authorize(function(error, tokens) {
    if (error) {
      console.log("Error making request to generate access token:", error);
    } else if (tokens.access_token === null) {
      console.log("Provided service account does not have permission to generate access tokens");
    } else {
      var accessToken = tokens.access_token;
      console.log('accessToken= ' + accessToken)
      // Include the access token in the Authorization header.
    }
  });


const service = google.cloudsearch({version: 'v1'});
service.query.search({
    auth: jwtClient,
    requestBody: {
      requestOptions: {
        searchApplicationId: 'searchapplications/default',
        debugOptions:{enableDebugging: true}
      },
      query: 'My query'
    }
  }).then((res) => {
  console.log(JSON.stringify({results:res.results.length}));
  console.log(JSON.stringify({resultsInfo:res.results[0]}));
}).catch((err) => {
  console.error('Unexpected error with cloud search API.');
  console.error(err.toString());
});