gilamran
gilamran

Reputation: 7294

Accessing GoogleDrive files using APIKey

I'm trying to create a nodejs app that can ready my GoogleDrive files. I don't want an app that everyone can use, it's only specific to my GoogleDrive. so no need for OAuth...

I've created an api key for GoogleDrive, in the console without any restrictions.

This is the call that I'm doing: https://www.googleapis.com/drive/v3/files?pageSize=10&fields=nextPageToken&key=MY_KEY

When using this key I get this error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "insufficientFilePermissions",
    "message": "The user does not have sufficient permissions for this file."
   }
  ],
  "code": 403,
  "message": "The user does not have sufficient permissions for this file."
 }
}

Is this even possible in GoogleDrive?

Do I have to set permissions somewhere?

What am I missing here?

Upvotes: 1

Views: 703

Answers (1)

Tanaike
Tanaike

Reputation: 201703

How about this answer?

Issue:

The API key is used for the publicly shared contents. So if you try to access to the file which is not shared publicly with the API key, an error occurs even if the file is yours.

And, API key can be used for GET method. The API key cannot be used for POST and PUT methods. Please be careful this.

Solution:

In order to access to your file on Google Drive, how about the following methods?

  1. Publicly share the file, and you access to the file with the API key.

    • In this case, the file cannot be written with API key even if the shared file is publicly shared as the editable permission.
  2. If you want to access the file without sharing publicly, how about using the access token retrieved by the Service account or OAuth2?

    • If the access token retrieved by OAuth2 is used, it is required to authorize by own browser.
    • If the service account is used, you can retrieve the access token without authorizing with own browser.

References:

Upvotes: 1

Related Questions