我正在尝试使用 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(认为双击 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 @ ]