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