0
我目前正試圖解決如何使用python從谷歌驅動器下載文件元數據。我幾乎只是從谷歌提供的文檔中複製/粘貼,到目前爲止一直沒有問題。當我嘗試撥打:在Python中使用Google API獲取文件元數據
drive_file = drive_service.files().get(id=file_id).execute()
我收到以下錯誤:
drive_file = drive_service.files().get(id=file_id).execute()
File "build\bdist.win-amd64\egg\apiclient\discovery.py", line 452, in method
TypeError: Got an unexpected keyword argument "id"
然而,谷歌文檔中有一個例子here(Python的標籤下),顯示幾乎完全一樣我擁有的東西。我的代碼不工作是因爲我缺乏Python經驗還是別的什麼?完整的程序顯示如下:
import httplib2
from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow
def getDriveService():
ClientID = <MY_CLIENT_ID>
ClientSecret = <MY_CLIENT_SECRET>
OAUTH_SCOPE = 'https://www.googleapis.com/auth/drive'
REDIRECT_URI = <MY_REDIRECT_URI>
flow = OAuth2WebServerFlow(ClientID, ClientSecret, OAUTH_SCOPE, REDIRECT_URI)
flow.redirect_uri = REDIRECT_URI
authorize_url = flow.step1_get_authorize_url()
print authorize_url
code = raw_input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)
http = httplib2.Http()
http = credentials.authorize(http)
return build('drive', 'v2', http=http)
drive_service = getDriveService()
files = drive_service.files().list().execute()
file_id = files['items'][0]['id']
#Error occurs here
drive_file = drive_service.files().get(id=file_id).execute()
print 'Title: %s' % drive_file['title']
print 'Description: %s' % drive_file['description']
print 'MIME type: %s' % drive_file['mimeType']
我不是太熟悉谷歌的API,但存在使用'得到的文檔的更新版本(FILEID =的file_id)'相反:https://developers.google.com/drive/v2/reference/files/get – 2013-03-12 21:50:10
試過,但沒有區別。 – LucasS 2013-03-12 23:57:20