2012-07-16 214 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安装流程。

相关问题