0
我正在嘗試從我的谷歌驅動器中檢索活動報告。 我已經創造了developper控制檯的項目,並啓動下列API: 聯繫SDK 審計API 驅動SDK 驅動API使用Python訪問Google雲端硬盤活動報告
我使用Python中下面的腳本:
import httplib2
import pprint
from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow
# Copy your credentials from the APIs Console
CLIENT_ID = '<My_Client_ID>'
CLIENT_SECRET = 'My_Client_Secret'
# Check https://developers.google.com/drive/scopes for all available scopes
OAUTH_SCOPE ='https://www.googleapis.com/auth/admin.reports.audit.readonly'
# Run through the OAuth flow and retrieve credentials
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE)
authorize_url = flow.step1_get_authorize_url('urn:ietf:wg:oauth:2.0:oob')
print 'Go to the following link in your browser: ' + authorize_url
code = raw_input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)
# Create an httplib2.Http object and authorize it with our credentials
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
headers = {'Authorization': 'Bearer realm=%s' %code}
(resp, content) = http.request(URL,"GET",headers=headers)
它返回我有一個無效的令牌。 我不知道什麼是不工作。 是我的http.request還是我沒有的某些管理員權限?
謝謝你的幫助!
正如您所提到的,您收到錯誤爲「無效令牌」,因此任一令牌可能已空或已過期。 Credentials對象包含授權訪問單個用戶數據的刷新和訪問令牌。如果請求有任何問題,您將收到不同的錯誤消息。請檢查令牌是否有效。希望有所幫助! – KRR 2015-02-06 23:50:43