授權客戶端還是範圍試圖運行我的代碼,當我得到這個錯誤: 谷歌API的Python unauthorized_client:在請求
oauth2client.client.AccessTokenRefreshError: unauthorized_client: Unauthorized client or scope in request.
這裏是我的代碼:
import json
import requests
import httplib2
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.discovery import build
if __name__ == '__main__':
json_key_file = 'my-key.json'
with open(json_key_file) as json_file:
json_data = json.load(json_file)
credential = SignedJwtAssertionCredentials(json_data['client_email'], json_data['client_email'], json_data['private_key'], scope=['https://www.googleapis.com/auth/admin.directory.user','https://www.googleapis.com/auth/admin.directory.user.readonly'], sub='[email protected]')
http = httplib2.Http()
http = credential.authorize(http)
service = build('admin', 'directory_v1', http=http)
data = service.users().list(domain='domain.com').execute()
print data
我有範圍集正確地在我的控制檯中,並且我的控制檯中啓用了我的Admin SDK。 我的電子郵件是一個可以訪問所有Admin API權限的超級管理員。
爲什麼我會得到這個錯誤?
https://developers.google.com/admin-sdk/directory/v1/guides/代表團我認爲你在創建服務帳戶和憑證下忘記了第一步。 – DaImTo 2014-12-04 13:52:15