Google 驱动器 API v3:无效的字段选择
Google Drive API v3: Invalid field selection
我正在使用 Google Drive API v3 来访问 space 配额之类的驱动器。
而且,无论我做什么,我都会遇到这个错误:
Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling **GET https://www.googleapis.com/drive/v3/about?fields=name**: (400) Invalid field selection name' in /var/webs/includes/google-api-php-client/src/Google/Http/REST.php:110
Stack trace:
#0 /var/webs/includes/google-api-php-client/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /var/webs/includes/google-api-php-client/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /var/webs/includes/google-api-php-client/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /var/webs/includes/google-api-php-client/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#5 /var/webs/includes/goog in /var/webs/includes/google-api-php-client/src/Google/Http/REST.php on line 110
$googleClient = $this->getClient();
$googleClient->setAccessToken($accessToken);
$googleDrive = new Google_Service_Drive($googleClient);
//fields can be found here: https://developers.google.com/drive/v3/web/migration#fields
$optParams = array(
'fields' => 'name'
);
print_r($googleDrive->about->get($optParams));
请检查我是否已经为通话制作了完美的 URL:
获取 https://www.googleapis.com/drive/v3/about?fields=name
但是,仍然存在这个错误。我缺少任何参数吗?
拜托,谁能告诉我 API 本身是否有问题?
在 v3 中,字段定义已更改,应该是
fields=storageQuota,user/displayName
而不是
fields=name
无论如何,我对PHP没有经验。
参考:
https://developers.google.com/drive/v2/reference/about
https://developers.google.com/drive/v3/reference/about
您可以自行检查所有可用字段:
现在这些是我找到的字段:appInstalled, exportFormats, folderColorPalette, importFormats, kind, maxImportSizes, maxUploadSize, storageQuota & user
.
如果您需要检查允许哪些字段,请转至 https://developers.google.com/drive/v3/reference/about/get 并执行 "Try It!".
用于获取包含我使用过的所有可能字段的文件 files/*
示例请求 https://www.googleapis.com/drive/v3/files?fields=files/*
发生此错误是因为 name
不是顶级密钥。有效的顶级键是:kind
、incompleteSearch
、nextPageToken
和 files
。要仅获取文件名,您必须使用 files/name
.
获取它
要获取 nextPageToken
和文件名,您可以执行以下操作:fields=nextPageToken,files/name
.
我正在使用 Google Drive API v3 来访问 space 配额之类的驱动器。
而且,无论我做什么,我都会遇到这个错误:
Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling **GET https://www.googleapis.com/drive/v3/about?fields=name**: (400) Invalid field selection name' in /var/webs/includes/google-api-php-client/src/Google/Http/REST.php:110
Stack trace:
#0 /var/webs/includes/google-api-php-client/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /var/webs/includes/google-api-php-client/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /var/webs/includes/google-api-php-client/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /var/webs/includes/google-api-php-client/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#5 /var/webs/includes/goog in /var/webs/includes/google-api-php-client/src/Google/Http/REST.php on line 110
$googleClient = $this->getClient();
$googleClient->setAccessToken($accessToken);
$googleDrive = new Google_Service_Drive($googleClient);
//fields can be found here: https://developers.google.com/drive/v3/web/migration#fields
$optParams = array(
'fields' => 'name'
);
print_r($googleDrive->about->get($optParams));
请检查我是否已经为通话制作了完美的 URL: 获取 https://www.googleapis.com/drive/v3/about?fields=name 但是,仍然存在这个错误。我缺少任何参数吗?
拜托,谁能告诉我 API 本身是否有问题?
在 v3 中,字段定义已更改,应该是
fields=storageQuota,user/displayName
而不是
fields=name
无论如何,我对PHP没有经验。
参考:
https://developers.google.com/drive/v2/reference/about
https://developers.google.com/drive/v3/reference/about
您可以自行检查所有可用字段:
现在这些是我找到的字段:appInstalled, exportFormats, folderColorPalette, importFormats, kind, maxImportSizes, maxUploadSize, storageQuota & user
.
如果您需要检查允许哪些字段,请转至 https://developers.google.com/drive/v3/reference/about/get 并执行 "Try It!".
用于获取包含我使用过的所有可能字段的文件 files/*
示例请求 https://www.googleapis.com/drive/v3/files?fields=files/*
发生此错误是因为 name
不是顶级密钥。有效的顶级键是:kind
、incompleteSearch
、nextPageToken
和 files
。要仅获取文件名,您必须使用 files/name
.
要获取 nextPageToken
和文件名,您可以执行以下操作:fields=nextPageToken,files/name
.