我正在尝试与Google进行身份验证以使用Google驱动器,但当我尝试列出文件时,没有人回来(我知道我的Google云端硬盘中有文件)。
我正在使用此代码,当我执行它时,没有列出任何文件。它是否尝试获取与我的帐户关联的文件blah@blah.com或298741233858@developer.gserviceaccount.com?因为我在blah@blah.com上有文件,但298741233858@developer.gserviceaccount.com刚刚为开发人员访问而创建。
from oauth2client.client import SignedJwtAssertionCredentials
import httplib2
from apiclient.discovery import build
email = 'blah@blah.com'
service_email = '298741233858@developer.gserviceaccount.com'
scope = 'https://www.googleapis.com/auth/drive'
f = file('google-api-key', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(service_email, key, scope=scope)
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
def get_all_files(service):
result = []
page_token = None
while True:
param = {}
if page_token:
param['pageToken'] = page_token
files = service.files().list(**param).execute()
result.extend(files['items'])
page_token = files.get('nextPageToken')
if not page_token:
break
return result
files = get_all_files(drive_service)
print files