如何使用 Cloud SQL API 从另一个项目拥有的 Cloud SQL 实例导出?

How do I export using Cloud SQL API from Cloud SQL instances owned by another project?

我正在尝试从另一个项目拥有的云 SQL 数据库中导出 table。调用项目具有访问权限并且可以成功列出实例(使用 getItems()),但是当我尝试导出时它是 returns "The client is not authorized to make this request."

这是我用来导出的代码。

$client = new Google_Client();
$client->setAuth(new Google_Auth_AppIdentity($client));
$client->getAuth()>authenticateForScope('https://www.googleapis.com/auth/sqlservice.admin');
$client->getAuth()>authenticateForScope('https://www.googleapis.com/auth/cloud-platform');
$sqladmin = new Google_Service_SQLAdmin($client);
$postBody = new Google_Service_SQLAdmin_InstancesExportRequest();

//Set csv options
$csv_options = new Google_Service_SQLAdmin_ExportContextCsvExportOptions();
$csv_options->setSelectQuery('SELECT id FROM test.test;');

//set export context options.
$ec = new Google_Service_SQLAdmin_ExportContext();
$ec->setCsvExportOptions($csv_options);

$ec->setUri('gs://bucket/file.csv');

$postBody->setExportContext($ec);

$response = $sqladmin->instances->export('testing-project-xxxx', 'database', $postBody);
$response = $sqladmin->instances->export('testing-project-xxxx', 'database', $postBody);

用实例名替换数据库名