You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python通过DBM API和Google服务账号OAuth自动拉取DV360报告

问题根因及修复方案

  1. Scope配置错误
    你当前配置的DBM API scope拼写不完整,正确的授权范围应为https://www.googleapis.com/auth/doubleclickbidmanager,你漏写了路径中的/auth/字段,这是触发scope不是有效受众字符串报错的核心原因。
    修正后的SCOPES配置:
SCOPES = [
    "https://www.googleapis.com/auth/spreadsheets", 
    "https://www.googleapis.com/auth/bigquery",
    "https://www.googleapis.com/auth/doubleclickbidmanager"
]
  1. API调用方法名错误
    DoubleClick Bid Manager v1.1接口的查询操作方法名没有后缀query:
  • 错误写法:dbm.queries().createquery(body=report_definition).execute()
  • 正确写法:dbm.queries().create(body=body).execute()
  • 查询列表的正确写法:dbm.queries().list().execute()
  1. 全域委托配置注意事项
    如果使用with_subject委托账号权限,需确认两个配置:
  • 传入的邮箱格式正确,不存在@.这类格式错误
  • 该账号已在DV360合作伙伴层级开通对应广告主的读写权限,同时Google Admin后台的全域委派已勾选该scope的授权
    如果你的服务账号已经直接添加到DV360并分配了管理员权限,不需要额外配置委托,直接使用原始服务账号凭证调用接口即可。
  1. 额外调试建议
    调用接口前可先刷新凭证验证授权是否正常:
from google.auth.transport.requests import Request
creds.refresh(Request())
print(creds.token)

如果这一步就报错,优先排查scope、服务账号全域权限配置是否正确。

内容的提问来源于stack exchange,提问作者bosh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 08:54:03