1

我正在尝试通过 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
4

0 回答 0