微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Google Ads API:使用服务帐户访问

如何解决Google Ads API:使用服务帐户访问

我正在尝试使用服务帐户连接到Google Ads API。对于分析,有一篇名为Hello Analytics API: Java quickstart for service accounts的好文章,其中介绍了如何进行设置。对于Google广告,我无法在线找到任何文档。

所以我的两个问题是:

  1. 是否可以使用服务帐户访问Google Ads API?
  2. 如果是,是否有类似“ Hello Ads API:服务帐户的Java快速入门”页面,其中包含有关如何使用服务帐户连接到api的信息?

更新2/10

我成功通过了身份验证。尝试从API提取数据时,确实收到错误消息。

curl.exe --request POST "https://googleads.googleapis.com/v5/customers/******/googleAds:searchStream"
--header "Content-Type: application/json" 
--header "Authorization: Bearer ******" 
--header "developer-token: ******" 
--data "{'query': 'SELECT * FROM campaign WHERE segments.date DURING YESTERDAY'}"

[{
  "error": {
    "code": 401,"message": "Request is missing required authentication credential. Expected OAuth 2 access token,login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status": "UNAUTHENTICATED","details": [
      {
        "@type": "type.googleapis.com/google.ads.googleads.v5.errors.GoogleAdsFailure","errors": [
          {
            "errorCode": {
              "authenticationError": "NOT_ADS_USER"
            },"message": "User in the cookie is not a valid Ads user."
          }
        ]
      }
    ]
  }
}
]

google文档说此错误是因为该帐户未与google ads帐户(https://developers.google.com/google-ads/api/docs/best-practices/common-errors#not_ads_user)相关联。该请求正在由api处理,我知道这是因为该请求在google ads api控制台中被视为错误

在与此Google Api Api的此API兼容的凭据中,列出了我的服务帐户。我对此错误感到有些困惑。据我所知,该服务帐户已与google ads帐户相关联。

解决方法

根据Google Ads API Service Accounts的警告:

注意:并非我们所有的客户端库当前都支持服务帐户。如果您自己实现OAuth2服务帐户流程,则仍然可以使用服务帐户。


关于两个问题:
  1. 是的,可以使用服务帐户(仅适用于Python和.NET)访问Ads API
  2. Google Ads API建议使用服务帐户流程,但它是not yet supported in Java

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。