I'm struggled with Google Drive REST API interface. I need to create a folder programmatically. Reading api documents (https://developers.google.com/drive/v3/reference/files/create) it's possible to create a folder with a POST method to https://www.googleapis.com/drive/v3/files, a request body with folder name and mime type as 'application/vnd.google-apps.folder'
so I write this python function:
def createFolder(self,folderName):
if not self.authorization:
self.get_authorization()
url = 'https://www.googleapis.com/drive/v3/files'
headers = { 'Authorization':'Bearer {}'.format(self.access_token)}
metadata = {
"name": folderName,
"mimeType": 'application/vnd.google-apps.folder'
}
response = requests.post( url, headers = headers, params = metadata)
return response.json()
that outputs a response object like this:
{
u'mimeType': u'application/json',
u'kind': u'drive#file',
u'id': u'0B350e2U7rvyvR0k3NjJmTTVuWUE',
u'name': u'Untitled'
}
A file is created, but the folder metadata are not applied. When I do the same with "Try it!" APIs Explorer I get a correct behaviour, so I can't understand where my code is wrong.
I'm writing a portable plugin and I don't want to deal with google library so I would prefer a simple Http approach.
I'll appreciate if you can give me any suggestions.
pydrive
. – asongtoruin