【发布时间】:2012-07-16 07:43:30
【问题描述】:
我正在尝试通过服务帐户(客户端电子邮件和 p12 证书)连接到 google doubeclick api,使用 python 客户端库,如下例所示:
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(认为双击 api 可能不是受支持的范围),但结果相同。
更新(示例代码):
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 @ ]
【问题讨论】:
-
不,也没有刷新令牌(它也是空白的)
-
尝试将
--dump_request_response作为附加的命令行标志传递。这应该将与服务器的对话转储到标准输出,这样您就可以看到出了什么问题。如果你在 [i]python 会话中运行(如上),你想做:import gflags; gflags.FLAGS.dump_request_response = True -
我收到了
KeyError: 'dump_request_response' -
糟糕——这是我的错误。 apiclient 使用该标志,而不是 oauth2client。你能检查任何其他返回的对象,看看是否有东西隐藏了错误消息吗?
-
看不到任何其他错误,我查看了凭据的所有属性。在[9]:凭证.无效输出[9]:假
标签: python google-api google-api-python-client