适用于云端硬盘的Google OAuth 2.0(服务帐户)中使用了哪些电子邮件?

时间:2012-10-17 16:13:25

标签: python oauth-2.0 google-openid google-authentication google-api-python-client

我正在尝试与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

0 个答案:

没有答案