我正在尝试访问 dbm api ,我正在使用服务帐户验证 url,请查找下面的示例代码
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
from httplib2 import Http
scopes =['https://www.googleapis.com/auth/doubleclickbidmanager']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'path/to/key/.jsonfile', scopes=scopes)
http_auth = credentials.authorize(Http())
body={}
dbm = build('doubleclickbidmanager', 'v1', http=http_auth)
print dbm
request = dbm.lineitems().downloadlineitems(body=body).execute()
print request
如果我使用oauth
验证 url 的机制代码是否正常运行,因为我不需要用户交互,所以我需要服务器到服务器机制,所以我使用了服务帐户
我尝试过的步骤:
我已经创建了服务帐户并下载了json
密钥文件并在代码中使用,但是当我尝试运行代码时,它会抛出以下错误:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/doubleclickbidmanager/v1/lineitems/downloadlineitems?alt=json returned "You are not authorized to use DoubleClick Bid Manager API. Please contact [email protected] /cdn-cgi/l/email-protection.">
请帮忙,提前致谢。
正如其他人在这里所说的,您想要登录 DBM 站点并将您的服务帐户添加为用户:
Then, 根据本文档 https://developers.google.com/identity/protocols/OAuth2ServiceAccount,您可以使用客户端机密 json 文件设置服务帐户凭据。如果您希望该服务帐户能够访问您在用户帐户(登录时使用的帐户)下在 DBM 中创建的报告,则需要委派域范围的权限:
delegated_credentials = credentials.create_delegated('[email protected] /cdn-cgi/l/email-protection')
http_auth = delegated_credentials.authorize(Http())
dbm = build('doubleclickbidmanager', 'v1', http=http_auth)
queries = dbm.queries().listqueries().execute()['queries']
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)