我试图通过服务帐户(客户端电子邮件和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