Monday, April 24, 2017

Google Drive API Error: The user has not granted the app XXXXX read access to the file YYYYYY

If you get an error like this one:


"error": {
"errors": [
{
"domain": "global",
"reason": "appNotAuthorizedToFile",
"message": "The user has not granted the app 183181265754 read access to the file 0B7unS-zlQOGYcjhnOUJkNDY5Z0E.",
"locationType": "header",
"location": "Authorization"
}
],
"code": 403,
"message": "The user has not granted the app 183181265754 read access to the file 0B7unS-zlQOGYcjhnOUJkNDY5Z0E."
}
}

Make sure you have DRIVE , METADATA and DRIVE_FILE scope permissions set in your client code. Like this (PHP):


define('SCOPES', implode(' ', array(
  \Google_Service_Drive::DRIVE_METADATA,
  \Google_Service_Drive::DRIVE_FILE,
  \Google_Service_Drive::DRIVE
 
 )

For example, if DRIVE is missing, it's going to return that error. Also, make sure that your service account's email is added to share list of the file/folder you're trying to access.

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...