繁体   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