2012-07-16 309 views
0

我試圖通過服務帳戶(客戶端電子郵件和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 @ ]

+0

是否有刷新令牌? – 2012-07-16 07:45:57

+0

沒有,也沒有刷新令牌(它也是空的) – 2012-07-16 07:46:29

+0

嘗試傳遞'--dump_request_response'作爲附加的命令行標誌。這應該將與服務器的對話轉儲到標準輸出,以便您可以看到發生了什麼問題。 如果您正在[i] python會話中運行(如上所述),您需要執行以下操作:import gflags; gflags.FLAGS.dump_request_response = True' – 2012-07-16 07:50:32

回答

0

的NO_NETWORKS_TO_ACCESS錯誤具體是指你沒有身份驗證的API端點,但您的帳戶ISN與網絡無關。在此頁上搜索該錯誤https://developers.google.com/doubleclick-publishers/docs/reference/v201203/InventoryService?hl=en

您或者需要讓您通過DoubleClick用戶界面邀請加入網絡的Google帳戶進行身份驗證,或者您需要使用模擬功能。

對DFP API和服務帳戶的更具體的說明最近發佈在文檔https://developers.google.com/doubleclick-publishers/docs/service_accounts。我建議您查看該文檔的替代部分,以確定您是否願意安裝OAuth 2.0安裝流程。

相關問題