Google Drive Root Folder File Not Found Error
-
12-12-2019 - |
Question
I had written a program that creates a file object, which by defaults gets created in the root folder if no parent is specified. Then given the id of the file's parent it retrieves the root folder.
For some strange reason this no longer works, instead of returning the root folder I get a File Not Found error. Any ideas?
Thanks
Update
I tried retrieving the file by passing in "root" as the file_id and I encountered the same error.
Get File By ID Error: File not found: 0AFrTA6Qc9-_TU9PVA
Below is the function used
def get_file_by_id session, file_id
drive = session.discovered_api("drive", "v2")
result = session.execute api_method: drive.files.get, parameters: {'fileId' => file_id}
if result.status == 200
return result.data
else
raise "Get File By ID Error: #{result.data['error']['message']}"
end
end
I am however able to get other file's by ID except the root.
Solution
Without seeing code, hard to say what you're doing wrong. But, there's a much easier way to go about getting the root folder for a user than what you're doing!
You can use the special 'root' ID to reference the root folder of the current user.
GET https://www.googleapis.com/drive/v2/files/root
That will return back info about the root folder. It's also available in the about collection.
Update: Details about the root folder are only available using the https://www.googleapis.com/auth/drive scope. When using the file scope, there isn't a way to 'open' the root folder from the Drive UI or Picker in order to authorize access by the app.