0

我在使用 googleapis/google-api-php-client库时遇到了一个问题,特别是我无法解决的数据流服务。

当我尝试使用该库时,我像这样设置请求:

$this->client = new \Google_Client();
$this->client->setAuthConfig(config_path('google-service-account.json'));
$this->client->setIncludeGrantedScopes(true);
$this->client->addScope(\Google_Service_Dataflow::CLOUD_PLATFORM);

$body = [
    "gcsPath" => "gs://{$this->bucket}/{$this->template}",
    "location" => "us-central1",
];

$parameters = new \Google_Service_Dataflow_LaunchTemplateParameters;
$parameters->setJobName($this->jobname);
$parameters->setParameters($body);

$service = new \Google_Service_Dataflow($this->client);
$request = $service->projects_templates->launch($this->project, $parameters);

我收到以下错误:

{
  "error": {
    "code": 400,
    "message": "(11f8b78933fc59c3): Bad file name: , expected 
    'gs://\u003cbucket\u003e/\u003cpath\u003e'",
    "errors": [
      {
        "message": "(11f8b78933fc59c3): Bad file name: , expected 
        'gs://\u003cbucket\u003e/\u003cpath\u003e'",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

似乎路径在此过程中被损坏了,我已经检查过了,直到 Guzzle 对象被实例化以在库中发送请求之前它都很好。

在这一点上我很迷茫,所以欢迎任何建议或线索。

先感谢您。

4

1 回答 1

1

SDK 构造的请求的查询参数中没有gcsPath给出。

这是因为 gcsPath 设置为Google_Service_Dataflow_LaunchTemplateParameters.

据记载,请求查询参数作为可选参数给出(参见https://github.com/googleapis/google-api-php-client-services/blob/v0.81/src/Google/Service/Dataflow/Resource/项目模板.php#L73 .)

$opt_params = [
    "gcsPath" => "gs://{$this->bucket}/{$this->template}",
    "location" => "us-central1",
];

$template_params = [
   // Keep template params here.
];

$launch_params = new \Google_Service_Dataflow_LaunchTemplateParameters;
$launch_params->setJobName($this->jobname);
$parameters->setParameters($template_params);

$service = new \Google_Service_Dataflow($this->client);
$request = $service->projects_templates->launch($this->project, $parameters, $opt_params);
于 2019-01-14T14:30:59.763 回答