【发布时间】:2019-03-23 23:59:23
【问题描述】:
我收到一封电子邮件,说明我的 Google Cloud 项目使用了计划于 2019 年 3 月 25 日关闭的全局 HTTP 批处理服务端点。
经过一番研究,我发现了一些可能相关的东西here,
“正在停止的是在一个批次中向多个不同的 API 发送请求......”
所以我怀疑这是因为我在 Google Cloud 项目中的代码:
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Sheets::SPREADSHEETS);
$client->addScope(Google_Service_Drive::DRIVE);
print_r($client);
//create new spreadsheet
$sheetService = new Google_Service_Sheets($client);
$requestBody = new Google_Service_Sheets_Spreadsheet([
'properties' => [
'title' => $new_sheet_title
]
]);
$response = $sheetService->spreadsheets->create($requestBody);
$spreadsheetId = $response->spreadsheetId;
$driveService = new Google_Service_Drive($client);
$client->setUseBatch(true);
$batch = $driveService->createBatch();
$userPermission = new Google_Service_Drive_Permission(array(
'type' => 'user',
'role' => 'writer',
'emailAddress' => 'mypersonalemail@gmail.com'
));
$request = $driveService->permissions->create(
$spreadsheetId, $userPermission, array('fields' => 'id'));
$batch->add($request, 'user');
$results = $batch->execute();
$client->setUseBatch(false);
//then no longer using Drive API, only using Sheet API to do formatting...
当我 print_r() 我的 $client 时,我看到了这个:
[requestedScopes:protected] => Array
(
[0] => https://www.googleapis.com/auth/spreadsheets
[1] => https://www.googleapis.com/auth/drive
)
我正在使用 Google Sheet API 创建电子表格并使用 Drive API 来允许访问我的个人电子邮件(嗯,为什么我使用这种方式是另一回事...) 顺便说一句,我正在使用 Google Client Library (v2.2.1) php beta
所以我想我要做的是
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
//using setScopes to overwrite original scopes
$client->setScopes(Google_Service_Sheets::SPREADSHEETS);
$sheetService = new Google_Service_Sheets($client);
//create my spreadsheet
$client->setScopes(Google_Service_Drive::DRIVE);
$driveService = new Google_Service_Drive($client);
//allow permission to my personal email
//then set it back & do formatting to my spreadsheet
$client->setScopes(Google_Service_Sheets::SPREADSHEETS);
$sheetService = new Google_Service_Sheets($client);
...
我测试过,肯定可以的
所以我的问题是:
1。我的代码的哪一部分正在向 Sheet 和 Driver API 发送批处理请求?当我检查我的批量更新请求时,没有找到调用这两个 API 的请求。 (参考here)
2。我不确定我的新脚本是否能解决问题。由于 Google 尚未拒绝该服务,因此我不确定我的新脚本是否会在 2019 年 3 月 25 日之后继续工作
我希望我清楚地表达我的担忧。随时询问更多细节。 在此先感谢:)
【问题讨论】:
标签: php google-api google-drive-api google-api-php-client google-sheets-api