簡體   English   中英

Google API服務帳戶

[英]Google API Service Account

我正在嘗試使用python客戶端庫通過服務帳戶(客戶端電子郵件和p12證書)連接到Google doubeclick 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 @ ]

NO_NETWORKS_TO_ACCESS錯誤專門表示您已向API端點進行了身份驗證,但您的帳戶未與網絡關聯。 在此頁面https://developers.google.com/doubleclick-publishers/docs/reference/v201203/InventoryService?hl=zh-CN上搜索該錯誤。

您要么需要擁有要通過DoubleClick用戶界面邀請到網絡進行身份驗證的Google帳戶,要么需要使用模擬功能。

最近在文檔中https://developers.google.com/doubleclick-publishers/docs/service_accounts發布了有關DFP API和服務帳戶的更具體的文章。 建議您查看該文檔的替代部分,以確定您是否更喜歡OAuth 2.0安裝流程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM