I am trying to set up a Google Drive Application using Service Account authentication with python. I have tried all the instructions I could find, but I can't get it to authorize the client. Here's what I've got:
CLIENT_EMAIL='<stuff>@developer.gserviceaccount.com'
f = open('<the .p12 file I downloaded from the OAuth section of the credentials page on the developers console>', 'rb')
key = f.read()
credentials = SignedJwtAssertionCredentials(CLIENT_EMAIL, key, scope='https://www.googleapis.com/auth/drive', sub="<the email address of the account owner listed in the permissions page>")
self.http = credentials.authorize(httplib2.Http())
gauth = GoogleAuth()
gauth.credentials = credentials
self.drive = GoogleDrive(gauth)
and later on in the code, this line
file_list = self.drive.ListFile({'q': "title = '" + id + '.zip' + "'", 'maxResults': 100}).GetList()
My code throws an unauthorized client exception
. I also tried pasting the private key from a JSon I downloaded directly into the code, and that doesn't work either. Decoding or encoding the key as base64 doesn't work (gives me some formatting error). Does anybody know what could be wrong?
I'm also running this on a server that isn't where I downloaded the p12 file, but I didn't think that mattered. I'm just mentioning it in case it does.
I too faced lot of issues while using google drive sdk. I wrote a little wrapper to make bit easy to use Google Drive Api (well atleast for me). You might find it helpful - google drive client wrapper gist