Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用服务帐户双击Bid manager api_Python_Google Api_Google Admin Sdk_Service Accounts_Double Click Advertising - Fatal编程技术网

Python 使用服务帐户双击Bid manager api

Python 使用服务帐户双击Bid manager api,python,google-api,google-admin-sdk,service-accounts,double-click-advertising,Python,Google Api,Google Admin Sdk,Service Accounts,Double Click Advertising,我正在尝试访问DBMAPI,我正在使用服务帐户验证url。请查找下面的示例代码 from oauth2client.service_account import ServiceAccountCredentials from apiclient.discovery import build from httplib2 import Http scopes =['https://www.googleapis.com/auth/doubleclickbidmanager'] credential

我正在尝试访问DBMAPI,我正在使用服务帐户验证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 dbm-support@google.com.">
googleapiclient.errors.HttpError:

请帮助,提前感谢。

服务帐户不是您,而是一个虚拟用户。例如,它有它的Google驱动器帐户,默认情况下,它没有访问任何双击投标管理器API的权限。服务帐户需要预先授权才能访问私人数据。因此,为了让它能够访问您的双击数据,您必须授予它访问权限


通常,对于任何其他API,我都会说您使用服务帐户电子邮件地址并将其添加为用户。我没有双击的权限,所以我甚至不确定您是否可以手动添加其他用户。他们的文档中没有任何关于服务帐户的内容,这让我觉得它不受支持。请告诉我们您是否能够使其正常工作。

正如其他人在此处所说,您希望登录到DBM站点并以用户身份添加您的服务帐户:

然后,您可以使用客户端机密json文件设置服务帐户凭据。如果您希望该服务帐户能够访问您在DBM中用户帐户(您登录时使用的帐户)下创建的报告,则需要授权域范围的权限:

delegated_credentials = credentials.create_delegated('user@example.org')
http_auth = delegated_credentials.authorize(Http())
dbm = build('doubleclickbidmanager', 'v1', http=http_auth)
queries = dbm.queries().listqueries().execute()['queries']

我接受你的观点“获取服务帐户电子邮件地址并将其添加为用户”,你能告诉我这样做的程序吗?我是否需要任何谷歌管理员帐户来授权?就像我说的,我没有双击出价帐户,所以我真的不知道你可能需要谷歌它。但是,是的,我会假设你需要是管理员双击出价帐户添加另一个用户,如果它甚至有可能添加另一个用户访问你的帐户account@Teejay我也遇到了同样的问题。添加了服务帐户的电子邮件地址,但我的代码仍会引发与您相同的错误。您已像其他任何用户一样授予服务帐户访问管理目录帐户的权限。除此之外,对不起,我帮不了你更多的忙。我实际上没有访问权限。更新:我刚刚将服务帐户电子邮件地址添加为DBM本身的一个用户。代码没有抛出任何错误,但我得到的响应是一个空体{}。也许你想试着告诉我们事情的进展。