Google Drive API v3:无效的字段选择

Reh*_*mat 4 php api drive google-drive-api

我正在使用Google Drive API v3访问有关空间配额的驱动器.

而且,无论我做什么,我都会遇到这个错误:

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));
Run Code Online (Sandbox Code Playgroud)

请检查我是否已经为通话制作了完美的网址:GET https://www.googleapis.com/drive/v3/about?fields=name 但是,仍然存在此错误.有什么参数我不见了吗?

请问,任何人都可以告诉我,如果API本身有问题吗?

小智 8

在v3中,字段定义已经改变,应该是

fields=storageQuota,user/displayName
Run Code Online (Sandbox Code Playgroud)

代替

fields=name
Run Code Online (Sandbox Code Playgroud)

无论如何,我没有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并执行"试用!".

  • 对我来说不明显的是字段范围 - 它是整个响应对象的范围.我正在使用`files list`并认为在返回的文件资源中应用了字段范围,但没有.即,我使用"id,size",但失败了."files/id,files/size"是有用的. (9认同)
  • @ChrisPrince 非常感谢您的评论。Google 的 API 记录非常糟糕,他们应该为自己感到羞耻。包含“fields”参数的页面上没有任何地方提到范围界定。 (2认同)

Dan*_*ana 6

用于获取包含我使用过的所有可能字段的文件 files/*

示例请求https://www.googleapis.com/drive/v3/files?fields=files/ *