Google 드라이브에서 활동 보고서를 가져 오려고합니다. 는 내가 developper 콘솔에서 프로젝트를 만든 다음 API 활성화 한 : 나는 파이썬에서 다음 스크립트를 사용하고 관리자 SDK 감사 API 드라이브 SDK 드라이브 APIPython을 사용하여 Google 드라이브 활동 보고서에 액세스
을 :
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