Rams P
Rams P

Reputation: 1

Google drive API method to get storage capacity gives error

REf url: https://developers.google.com/drive/v2/reference/about/get

When I am using the about methods, getting below error:

An error occurred: { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "The 'fields' parameter is required for this method.", "locationType": "parameter", "location": "fields" } ], "code": 400, "message": "The 'fields' parameter is required for this method." } }

This is my code:

function printAbout() {
    try {
        $about = $this->service->about->get(array('fields' => 'name'));
        print "Current user name: " . $about->getName();
        print "Root folder ID: " . $about->getRootFolderId();
        print "Total quota (bytes): " . $about->getQuotaBytesTotal();
        print "Used quota (bytes): " . $about->getQuotaBytesUsed();
    } catch (Exception $e) {
        print "An error occurred: " . $e->getMessage();
    }
}

Upvotes: 0

Views: 1009

Answers (2)

Kristof van Woensel
Kristof van Woensel

Reputation: 193

For Node.js, this works:

var drive = google.drive({ version: 'v3', auth: authClient }); 
drive.about.get({
   auth: authClient,
   fields: ["storageQuota"]
}, function (err, resp) {
   if(err) console.log(err);
   console.log(resp)
});

Upvotes: 0

Grant Watters
Grant Watters

Reputation: 670

If you haven't figured this out yet I've got your answer.

You are linking to the V2 version of the documentation but you are using V3 in your code. In V2, you do not need to specify the fields param and thus it should run completely fine through the API tester. It is likely that you linked the V2 documentation in your post but are using the V3 documentation yourself to do the testing.

The /drive/about/get API changed from V2 to V3. Specifically the layout of the returned information is not different. So when you specify 'name' as a field, it doesn't exist and you continue to get that (fairly unhelpful) error.

To fix your problem

Specify 'user' in the 'fields' param rather than 'name' and it will return the data that you want in result.user.displayName.

Documentation

V2 About/Get Result Documentation

V3 About/Get Result Documentation

I hope that the explanation is helpful and that you can properly get your data!

Upvotes: 1

Related Questions