Google app engine 谷歌云任务:定位';欧洲西部1';不是有效的位置

Google app engine 谷歌云任务:定位';欧洲西部1';不是有效的位置,google-app-engine,google-cloud-platform,google-cloud-tasks,Google App Engine,Google Cloud Platform,Google Cloud Tasks,我尝试使用云函数运行Google Cloud Tasks任务,但遇到了一个错误,我尝试使用的任何区域都是错误的 代码是基本的。在由于以下错误而停止之前,一切正常: 错误:{“代码”:3,“消息”:“位置'europe-west1'不是有效位置。。请使用ListLocations列出有效位置。”,“详细信息”:[] 例如,如果我尝试使用us-central1,它将报告: 错误:{“代码”:3,“消息”:“位置必须等于europe-west1,因为与此项目关联的应用程序引擎应用程序位于europe-

我尝试使用云函数运行Google Cloud Tasks任务,但遇到了一个错误,我尝试使用的任何区域都是错误的

代码是基本的。在由于以下错误而停止之前,一切正常:

错误:{“代码”:3,“消息”:“位置'europe-west1'不是有效位置。。请使用ListLocations列出有效位置。”,“详细信息”:[]

例如,如果我尝试使用us-central1,它将报告:

错误:{“代码”:3,“消息”:“位置必须等于europe-west1,因为与此项目关联的应用程序引擎应用程序位于europe-west1”,“详细信息”:[]}

我将Google Cloud Tasks API与Node.js一起用于创建新任务:

const client = new CloudTasksClient({ fallback: true }); 
const parent = client.queuePath(PROJECT, 'europe-west1', QUEUE);
以下是一个完整的示例:

名为的URL为: “$rpc/google.cloud.tasks.v2beta3.CloudTasks/CreateTask”

如果运行“位置列表”命令,则输出如下:

$ gcloud tasks locations list
europe-west1    projects/[project-id]/locations/europe-west1
编辑:在相同的配置下使用RESTAPI()可以工作。这可能是客户端的一个bug

我真的不确定我的设置有什么问题


不确定哪些信息对调试有帮助,因此如果没有足够的信息,请提前道歉。

我意识到您使用的示例适用于非应用程序引擎/云功能环境,请尝试中的简单示例

请检查您的package.json,您正在定义最新版本的google cloud/tasks库,目前它是1.9.0

您不需要在应用程序引擎/云功能环境中使用Ouath令牌,因为它们已经配置了服务帐户

// Imports the Google Cloud Tasks library.
  const {CloudTasksClient} = require('@google-cloud/tasks');

  // Instantiates a client.
  const client = new CloudTasksClient();

  // TODO(developer): Uncomment these lines and replace with your values.
  // const project = 'my-project-id';
  // const queue = 'my-appengine-queue';
  // const location = 'us-central1';
  // const payload = 'hello';

  // Construct the fully qualified queue name.
  const parent = client.queuePath(project, location, queue);

  const task = {
    appEngineHttpRequest: {
      httpMethod: 'POST',
      relativeUri: '/log_payload',
    },
  };

  if (payload) {
    task.appEngineHttpRequest.body = Buffer.from(payload).toString('base64');
  }

  if (inSeconds) {
    task.scheduleTime = {
      seconds: inSeconds + Date.now() / 1000,
    };
  }

  const request = {
    parent: parent,
    task: task,
  };

  console.log('Sending task:');
  console.log(task);
  // Send create task request.
  const [response] = await client.createTask(request);
  const name = response.name;
  console.log(`Created task ${name}`);

我意识到您使用的示例适用于非应用程序引擎/云功能环境,请尝试中的简单示例

请检查您的package.json,您正在定义最新版本的google cloud/tasks库,目前它是1.9.0

您不需要在应用程序引擎/云功能环境中使用Ouath令牌,因为它们已经配置了服务帐户

// Imports the Google Cloud Tasks library.
  const {CloudTasksClient} = require('@google-cloud/tasks');

  // Instantiates a client.
  const client = new CloudTasksClient();

  // TODO(developer): Uncomment these lines and replace with your values.
  // const project = 'my-project-id';
  // const queue = 'my-appengine-queue';
  // const location = 'us-central1';
  // const payload = 'hello';

  // Construct the fully qualified queue name.
  const parent = client.queuePath(project, location, queue);

  const task = {
    appEngineHttpRequest: {
      httpMethod: 'POST',
      relativeUri: '/log_payload',
    },
  };

  if (payload) {
    task.appEngineHttpRequest.body = Buffer.from(payload).toString('base64');
  }

  if (inSeconds) {
    task.scheduleTime = {
      seconds: inSeconds + Date.now() / 1000,
    };
  }

  const request = {
    parent: parent,
    task: task,
  };

  console.log('Sending task:');
  console.log(task);
  // Send create task request.
  const [response] = await client.createTask(request);
  const name = response.name;
  console.log(`Created task ${name}`);

生成错误消息的命令是什么?如果该命令需要一个区域或区域?嗨,John,我正在使用Google Cloud Tasks API创建一个新任务:``const client=new CloudTasksClient({fallback:true});const parent=client.queuePath(PROJECT,'europe-west1',QUEUE);``调用的URL是:“从我所见,参数名为“location”。如果运行“位置列表”命令,则输出如下:▶ gcloud任务位置列表名称全名europe-west1项目/[project id]/位置/europe-west1请勿发表评论。编辑您的问题并包含更多信息。我不确定,但我认为您需要将区域指定为
projects/[project id]/locations/europe-west1
我也尝试了
europe-west
,但返回了相同的错误。我认为客户端将使用通过SDK传递的信息构建该URL,但我可以尝试使用它执行手动调用生成错误消息的命令是什么?如果命令需要一个区域或区域?嗨,John,我正在使用Google Cloud Tasks API创建一个新任务:``const client=new CloudTaskClient({fallback:true});const parent=client.queuePath(项目'europe-west1',队列);`调用的URL是:“据我所见,参数名是“location”。如果我运行locations list命令,这就是输出:▶ gcloud tasks locations list NAME全名\u NAME europe-west1 projects/[project id]/locations/europe-west1请勿发表评论。编辑您的问题并包含更多信息。我不确定,但我认为您需要将区域指定为
projects/[project id]/locations/europe-west1
我也尝试了
europe-west
,但返回了相同的错误。我认为客户端将使用通过SDK传递的信息构建该URL,但我可以尝试使用该URL执行手动调用