Reputation: 2299
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?
Upvotes: 10
Views: 15196
Reputation: 6340
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
.
Upvotes: 4
Reputation: 3408
for getting files with all the possible fields I've used files/*
example request https://www.googleapis.com/drive/v3/files?fields=files/*
Upvotes: 7
Reputation: 877
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!".
Upvotes: 13