我尝试使用Google_Service_BigQueryDataTransfer。 我创建了服务帐户并下载了json文件。 我为GOOGLE_APPLICATION_CREDENTIALS设置了json文件的完整路径。 创建GoogleClient和Google_Service_BigQueryDataTransfer错误Google_Service_BigQueryDataTransfer
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes(array(
Google_Service_Bigquery::BIGQUERY
)
);
$this->service = new Google_Service_BigQueryDataTransfer($client);
我得到源
$this->service->projects_dataSources->
listProjectsDataSources('projects/' . self::PROJECT_ID);
的列表它工作正常。
我得到转移
$this->service->projects_locations_transferConfigs->
listProjectsLocationsTransferConfigs(
'projects/' . self::PROJECT_ID . '/locations/eu'
);
它也可以正常工作的列表。
我拿到证书
$this->service->projects_locations_dataSources->
checkValidCreds(
'projects/'.self::PROJECT_ID.'/locations/europe/dataSources/adwords',
new Google_Service_BigQueryDataTransfer_CheckValidCredsRequest()
);
或
$this->service->projects_dataSources->checkValidCreds(
'projects/'.self::PROJECT_ID.'/dataSources/adwords',
new Google_Service_BigQueryDataTransfer_CheckValidCredsRequest()
);
两个请求返回null
object(Google_Service_BigQueryDataTransfer_CheckValidCredsResponse)[174]
public 'hasValidCreds' => null
........
和最后我尝试创建传输
$params = new Google_Service_BigQueryDataTransfer_TransferConfig();
$params->setDestinationDatasetId('stat');
$params->setDisplayName('ID' . $adword_id);
$params->setDataSourceId(self::DATA_SOURCE_ID);
$params->setDataRefreshWindowDays(10);
$params->setDisabled(false);
$params->setParams(['customer_id'=> (string)$adword_id]);
return $this->service->projects_locations_transferConfigs->create(
$this->getParent(). '/locations/europe',
$params
);
,并有错误
Google_Service_Exception: {
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
我从
页https://cloud.google.com/bigquery/docs/reference/datatransfer/rest/v1/projects.transferConfigs/create
有这个错误时,没有存取BigQuery。 现在我使用服务帐户,可以列出数据源和传输,但不能创建数据传输。
你能说,我做错了吗?
工作代码
$this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials();
$this->client->setAuthConfig('client_secret.json');
$this->client->setAccessType("offline");
$this->client->setIncludeGrantedScopes(true);
$this->client->setScopes(array(
Google_Service_Bigquery::BIGQUERY,
ADWORDS_SCOPE
)
);
$this->client->setRedirectUri(self::REDIRECT_URI);
$url = $this->getAuthUrl();
header('Location: ' . filter_var($url, FILTER_SANITIZE_URL));
后,我在谷歌授权并给予访问。 我重定向到代码
$this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials();
$this->client->setAuthConfig(MCC_DIR . 'protected/config/client_secret.json');
$this->client->setAccessType("offline");
$this->client->setIncludeGrantedScopes(true);
$this->client->setScopes(array(
Google_Service_Bigquery::BIGQUERY,
ADWORDS_SCOPE
)
);
$this->client->setRedirectUri(self::REDIRECT_URI);
$code = $_GET['code'];
$this->client->authenticate($code);
$tokken = $this->client->getAccessToken();
$this->client->setAccessToken($tokken);
$this->service = new Google_Service_BigQueryDataTransfer($this->client);
$this->service->projects_locations_dataSources->checkValidCreds(
'projects/1069829667403/locations/europe/dataSources/adwords',
new Google_Service_BigQueryDataTransfer_CheckValidCredsRequest()
);
和一切工作
谢谢,没事,所有的作品。 –