我試圖通過服務帳戶(客戶端電子郵件和P12證書)來連接到谷歌doubeclick API,使用Python客戶端庫如下面的例子:谷歌API服務帳戶
http://code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py
它返回給我一個空的access_token:
In [9]: type(credentials.access_token)
Out[9]: <type 'NoneType'>
這是什麼意思?有什麼我可能做錯了嗎?我也嘗試訪問示例中的任務api(認爲可能doubleclick api不是受支持的範圍),但結果相同。
UPDATE(示例代碼):
from oauth2client.client import SignedJwtAssertionCredentials
import httplib2
from adspygoogle.dfp import DfpClient
f = file('/path/to/.ssh/google-api.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials('<email>', key, scope='https://www.google.com/apis/ads/publisher')
credentials.refresh(http)
http = httplib2.Http()
http = credentials.authorize(http)
client = DfpClient.DfpClient(headers={'networkCode': '<code>', 'applicationName': 'test', 'userAgent': 'test', 'oauth2credentials': credentials})
inventory_service = client.GetInventoryService()
inventory_service.getAdUnitsByStatement({'query':''})
錯誤:
DfpAuthenticationError: [AuthenticationError.NO_NETWORKS_TO_ACCESS @ ]
是否有刷新令牌? – 2012-07-16 07:45:57
沒有,也沒有刷新令牌(它也是空的) – 2012-07-16 07:46:29
嘗試傳遞'--dump_request_response'作爲附加的命令行標誌。這應該將與服務器的對話轉儲到標準輸出,以便您可以看到發生了什麼問題。 如果您正在[i] python會話中運行(如上所述),您需要執行以下操作:import gflags; gflags.FLAGS.dump_request_response = True' – 2012-07-16 07:50:32