Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive API returns errors "Invalid value" and "Invalid query" when requesting AppDataFolder

I was trying to request the list of all files that located in the AppDataFolder.

When I make the following request:

GET https://www.googleapis.com/drive/v2/files?spaces=appDataFolder&maxResults=1000 HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer <MyToken>
User-Agent: <MyUserAgent>

I get the following error:

HTTP/1.1 400 Bad Request
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid query",
    "locationType": "parameter",
    "location": "q"
   }
  ],
  "code": 400,
  "message": "Invalid query"
 }
}

Why does it ask me for a query if I just want to get the list of all files? Is the "q" parameter mandatory? I thought that it was some error in my code, so I downloaded the latest Google Drive SDK for Python and got the same error.

I tried to add the "q" parameter like q=title != 'foo' but it also returned Ivalid query error. Strange thing is that I can get my files list if I add the following query: q=title='<myfolder>' or title='<file1 in my folder>' or title='<file2 in my folder>'..., but if I remove title='<myfolder>' I get query error again.

I also tried another request, but it returned me an empty list, though I know that there are files in AppDataFolder:

GET https://www.googleapis.com/drive/v2/files?q='appfolder'+in+parents&access_token=<MyToken>

UPDATE: Looks like this issue is specific to a certain account. I tested all these requests with another account and get all the files hidden in appdatafolder. The requests that work:

https://www.googleapis.com/drive/v2/files?spaces=appDataFolder
https://www.googleapis.com/drive/v2/files?q='appDataFolder'+in+parents
https://www.googleapis.com/drive/v2/files?q='appfolder'+in+parents

What can be wrong with the first account?

UPDATE 2: I cannot retrieve the appdata files list from other accounts anymore. Looks like something happens with the API.

like image 306
Maxim Avatar asked Apr 12 '18 12:04

Maxim


People also ask

How do I stop read timeout?

Considering that Read Timeout is generally caused by long processing time on server side, I would suggest you to decrease this number to 500 or 200. I encountered same problems when I am fetching changes using max result count 1000. When I change the size to 200 or 500, it works smoothly.

Is there a Google Drive API?

The Google Drive API allows you to create apps that leverage Google Drive cloud storage. You can develop applications that integrate with Drive, and create robust functionality in your application using the Drive API.

Is Google Drive API free?

Pricing. All use of the Drive API is available at no additional cost.


1 Answers

The 'Application Data folder' is a special folder that is only accessible by your application. Its content is hidden from the user, and from other apps. Despite being hidden from the user, the Application Data folder is stored on the user's Drive and therefore uses the user's Drive storage quota. The Application Data folder can be used to store configuration files, saved games data, or any other types of files that the user should not directly interact with.

Even though users can't see the Application Data folder's content, they can see the amount of storage used by your app’s Application Data Folder in the Manage Apps dialog

Request:

GET https://www.googleapis.com/drive/v3/files?q='appDataFolder'+in+parents&key={YOUR_API_KEY}

Respose:

{
 "kind": "drive#fileList",
 "incompleteSearch": false,
 "files": [
 ]
}

Testing using Google Apis Explorer returns 0 files because Google apis explorer client has not uploaded any files to my google drive account.

Anwser: The files in the Appdata folder are owned by the application that created them. If you arnt seeing any files in the users app data folder then i would suggest that that you are using the wrong client and there for cant see any files your application may have uploaded.

Correct use of q

As stated in the documentation the correct use of q for searching the app data folder is.

'appDataFolder' in parents

AppData documentation.

Update :

q=title='' or title='' or title=''..., but if I remove title=''

If these are working and the parent of the files is not stating appdata then i would suggest that you have uploaded the files in the users main Google drive account rather then uploading them to appdata. This is a bad idea because then the user will be able to see the files they may not be able to edit them which will cause them a lot of confusion. if you have it in a folder and have not granted them permission to it the user may not actually be able to see the file not sure on this one.

Update 2:

q='appDataFolder' in parents

Will return all files created by your app with the parent folder of appDataFolder.

q='appfolder' in parents

Will return all files with the parent folder of appfolder which is actually a directory on the users Google Drive account and not the hidden appDataFolder

spaces='drive'

This means that the data is stored on drive.

spaces=appDataFolder

This is to request application data but this is only supported in V3 i think

like image 123
DaImTo Avatar answered Sep 18 '22 20:09

DaImTo