9

I am using Google Drive API v3 to access about the drive like space quota.

And, no matter what I do, I am stuck with this error:

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));

Please check that I am already making a perfect URL for the call: GET https://www.googleapis.com/drive/v3/about?fields=name But, still there is this error. Is there any parameter I am missing?

Please, can anyone tell me if there is problem with the API itself?

kinghfb
  • 1,011
  • 5
  • 14
Rehmat
  • 2,121
  • 2
  • 24
  • 28

3 Answers3

12

In v3 the fields definition has changed, it should be

fields=storageQuota,user/displayName

instead of

fields=name

Anyway, I have no exprience with PHP.

Ref:
https://developers.google.com/drive/v2/reference/about https://developers.google.com/drive/v3/reference/about


You can check yourself all the fields available: For now these were the fields I found: appInstalled, exportFormats, folderColorPalette, importFormats, kind, maxImportSizes, maxUploadSize, storageQuota & user.

If you need to check which fields are allowed, please go to https://developers.google.com/drive/v3/reference/about/get & do "Try It!".

Rehmat
  • 2,121
  • 2
  • 24
  • 28
some1
  • 857
  • 5
  • 11
  • You are right. But, I made the discovery myself already using v3 doc page and authorising my account for that. I got that these fields are allowed: **GET https://www.googleapis.com/drive/v3/about?fields=appInstalled%2CexportFormats%2CfolderColorPalette%2CimportFormats%2Ckind%2CmaxImportSizes%2CmaxUploadSize%2CstorageQuota%2Cuser&key={YOUR_API_KEY}** So, it is: `appInstalled, exportFormats, folderColorPalette, importFormats, kind, maxImportSizes, maxUploadSize, storageQuota & user`. But, really thanks for replying. – Rehmat Aug 10 '16 at 07:07
  • 23
    What wasn't obvious to me here was the fields scoping-- it's scoped over the entire response object. I was using `files list` and thinking the fields scoping applied within the files resource returned, but no. i.e., I was using "id, size" but that failed. "files/id,files/size" is what worked. – Chris Prince Jan 21 '17 at 23:51
  • 2
    @ChrisPrince Thank you so much for that comment. Google's API is documented exceptionally poorly and they should be ashamed of themselves. No where on the page containing the `fields` parameter is there any mention of scoping. – Jake Z Jul 20 '17 at 19:18
  • thanks, with php client api I used: $about = $driveService->about->get(array('fields'=>'storageQuota/limit,storageQuota/usage')); – Nagy Istvan Oct 18 '17 at 06:19
  • 1
    the scoping is what got me. I also had an abysmal time drudging through their api docs. Very poorly organized and even the api itself seems to expose access to their underlying structure instead of a friendly public interface – aaaaaa Oct 05 '19 at 16:05
6

for getting files with all the possible fields I've used files/*

example request https://www.googleapis.com/drive/v3/files?fields=files/*

Dan Ochiana
  • 3,340
  • 1
  • 30
  • 28
2

This error occurs because name is not a top level key. The valid top level keys are: kind, incompleteSearch, nextPageToken, and files. To get just the file's name you have to fetch it using files/name.

To get the nextPageToken and the file names you can do the following: fields=nextPageToken,files/name.

rohithpr
  • 6,050
  • 8
  • 36
  • 60