Ich schreibe ein Python-Skript versucht, Google-Laufwerk verbinden über Drive Api v3Google-Laufwerk api authentifizierten Http Anfrage Rückkehr 403 response "Der Benutzer die App xxxx Lesezugriff nicht erteilt hat xxxxxx in Datei"
# -*- coding: UTF-8 -*-
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.file import Storage
import os
import httplib2
import gdata.docs.service
import gdata.docs.client
import gdata.docs.data
from apiclient.discovery import build
import io
from apiclient.http import MediaIoBaseDownload
'''
starrt the Authintication Process for Google APi
'''
FLOW = OAuth2WebServerFlow(client_id="****************************",\
client_secret="************************",\
scope="https://www.googleapis.com/auth/drive",
redirect_uri="urn:ietf:wg:oauth:2.0:oob",
user_agent="PythonFileEditor/1.0")
OUT_PATH = os.path.join(os.path.dirname(__file__), 'out')
CREDS_FILE = os.path.join(os.path.dirname(__file__), 'credentials.json')
if not os.path.exists(OUT_PATH):
os.makedirs(OUT_PATH)
storage = Storage(CREDS_FILE)
credentials = storage.get()
if credentials is None:
authorize_url = FLOW.step1_get_authorize_url()
print 'Go to the following link in your browser: ' + authorize_url
code = raw_input('Enter verification code: ').strip()
try:
credentials = FLOW.step2_exchange(code)
except SystemError:
print SystemError
storage.put(credentials)
'''Authintication Process is Over'''
http = httplib2.Http()
http = credentials.authorize(http)
auth2tocken = gdata.gauth.OAuth2TokenFromCredentials(credentials)
service = build('drive', 'v3', http=http)
results = service.files().list(\
pageSize=10,fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print('{0} ({1})'.format(item['name'].encode('utf8'), item['id']))
if item.get('name')=='TestPY.txt':
fileId=item['id']
request = service.files().get_media(fileId=fileId)
fh = io.FileIO(item['name'])
downloader =MediaIoBaseDownload(fh,request)
done = False
while done is False:
status, done = downloader.next_chunk()
print "Download %d%%." % int(status.progress() * 100)
Dieses Skript, versuchen Sie, die Datei namens "TestPY.txt" von meinem Google Drive auf meine lokale Maschine herunterzuladen, der Authentifizierungsprozess scheint in Ordnung, wie ich die Dateinamen und IDs bekommen kann, aber wenn ich versuche, meine Datei, die API herunterzuladen Werfen Sie diese Ausnahme
raise HttpError(resp, content, uri=self._uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/0Bw2Q7p_e5q0-SFpGUURMSWptV3M?alt=media returned "The user has not granted the app ************** read access to the file 0Bw2Q7p_e5q0-SFpGUURMSWptV3M.">
Mein Bereich ist voll privilegiert, so Theoretiker Ich sollte in der Lage sein, jede Datei herunterzuladen/hochzuladen/zu lesen/schreiben!
kann mir irgendjemand in die richtige Richtung zeigen?
Danke euch allen.