python - Google Ads API - "failed with status "PERMISSION_DENIED”- "User doesn' 没有访问客户的权限。”

标签 python google-ads-api

我正在尝试使用 Google-ads-API。运行 Ubuntu 20.04、Python 3.9(客户端库运行的最低要求是 3.6),使用 google-ads-api V6。这是我痛苦的故事。
我已经创建了一个测试经理帐户 [A],生成了一个开发人员的 token ,并且拥有使用 API 的“测试级别”访问权限,这很棒。测试级别允许您调用有关处理测试帐户(非生产)的信息\报告的 API。
此外,通过帐户 [A] 的整个 Oauth2 凭据,允许测试电子邮件,并在运行“examples/authentication/authenticate_in_web_application.py”后,我被重定向到一个网页,允许我的主要测试经理帐户访问第二个测试经理帐户[B](按照文档的指示,创建另一个测试经理帐户[B],除了带有开发者 token 的主帐户[A]),从此OAuth2提示成功生成刷新 token ,以允许帐户[B] ] 管理我的帐户 [A],将刷新 token 添加到我的 google-ads.yaml 文件中,一切都很好。
当我从示例中运行这个 .py 文件时

python3 google-ads-python/examples/account_management/list_accessible_customers.py
结果是这样的:
Total results: 2
Customer resource name: "customers/1792845307"
Customer resource name: "customers/5341438919"
可爱,花了 2 天时间才走到这一步。现在已经两天了,试图通过以下。
请注意,以上结果均来自我的帐户 [B],获取这些结果的 API 请求是在 google-ads.yaml 文件中设置帐户 [A] 的开发人员 token 时发出的。
因此,.yaml 文件现在包含帐户 [A] 的开发者帐户 token 、云控制台 (.json) 文件中帐户 [A] 的 OAuth 凭据。由步骤 1 中的身份验证产生的帐户 [B] 的刷新 token 。
继续,通过运行“get_account_information.py”,它也在示例文件夹中,并将上述结果中的一个帐户传递给它[强制标志 --c,这是客户端 ID),我不断获得访问权限拒绝错误:python3 get_account_information.py --c 5341438919我明白了:
Request with ID "LhKeU9ZI4zZgnp05VSHbjg" failed with status "PERMISSION_DENIED" and includes the following errors:
Error with message "User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header. See https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid".```

我尝试设置“经理的客户 ID 必须设置在 'login-customer-id' 中”,这个 login-customer-id 位于 .yaml 文件中。我已尝试将其设置为步骤 2 中调用的结果。我还尝试从帐户 [A] 添加帐户经理 ID。我尝试使用 google-ads 的 UI 手动添加帐户 [A] 作为帐户 [B] 的帐户经理,然后尝试为所有这些链接过程再次为所有这些帐户设置“登录客户 ID”,但失败了。
对于示例目录中的所有 .py 文件,我正面临此访问被拒绝的问题。在这个冗长的过程中尽量做到彻底和详细,希望它有意义。如果您尝试使用此 API,您就会明白我的意思,并且我期待任何有关此的见解\帮助\输入,即使您尚未使用此 API。
在文档中,指南说创建一个测试开发者经理帐户后,下面的所有帐户也将是测试帐户,并且会被一个写着“TEST”的红色标签指定,否则它是一个生产帐户。上面的两个帐户 [A]+[B] 都是测试经理\开发人员帐户,但没有任何红色标签表明它们是测试,也没有我尝试在它们下创建的任何子项。所以我想知道我面临的错误\障碍是否是由于他们没有被指定为测试帐户?但是为什么它们在 Step2 中被列为“可访问帐户”。
非常感谢!如果需要任何其他信息,我将提供。

最佳答案

- - - - - - - 解决了 - - - - - - -
更新,就在几个小时后。我使用问题中提到的经理帐户 [B] 中使用的相同电子邮件创建了另一个新经理帐户。遵循与上述相同的步骤,但这次创建后,我得到了这个“RED TEST ACCOUNT FLAG”。
enter image description here
在大约一百次之前的尝试之后,我在终端中运行了它,这是第 678 次:

u@ROOT:~/google-ads-python$ python examples/account_management/list_accessible_customers.py

[2021-01-12 11:30:08 - INFO] Request made: ClientCustomerId: None, Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v6.services.CustomerService/ListAccessibleCustomers, RequestId: XIkvfX4b-xxNql705r_jbQ, IsFault: False, FaultMessage: None
Total results: 3
Customer resource name: "customers/1792845307"
Customer resource name: "customers/5341438919"
Customer resource name: "customers/3740041699"
因此,实际识别为测试的新帐户是“3740041699”。记下这个数字,它在 google-ads.yaml 文件中。在“login_customer_id:”下添加它,因为它是一个“经理帐户”[B],它管理我在它下创建的子帐户。编号为 991738295。
我的 .YAML 看起来像这样
# OAuth2 configuration
###############################################################################
# The below configuration parameters are used to authenticate using the       #
# recommended OAuth2 flow. For more information on authenticating with OAuth2 #
# see: https://developers.google.com/google-ads/api/docs/oauth/overview       #
###############################################################################

    developer_token: ******** #[ from Account A]
    client_id: ******.apps.googleusercontent.com #[From account A's email, that was used in google cloud console for API OAuth2]
    login_customer_id: 3740041699 [The manager test account B, mentioned above]
    client_secret: ******** #[From account A's email, that was used in google cloud console for API OAuth2]
    refresh_token: 1//********* [After authenticating account A to have access to account B]
现在当在上面运行樱桃时,我们有这个:
u@ROOT:~/examples/basic_operations/get_campaigns.py -c 9917382925 #ID of child of test manager mentioned above, this is the result: 

Campaign with ID 12058644642 and name "Website traffic-Search-1" was found.
[2021-01-12 11:36:39 - INFO] Request made: ClientCustomerId: 9917382925, Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v6.services.GoogleAdsService/SearchStream, RequestId: Py4oeSqyYiQpBFIWuRYgEg, IsFault: False, FaultMessage: None
这正是那里的东西,如下图所示:
enter image description here
终于在5天后。现在它正在工作,实际上开始开发。如果有人在使用 python 客户端并发现这很有用,我将不胜感激,建议有关服务器和路由的任何最佳实践或他们在使用这个有趣的 API 开发时学到的东西。
谢谢!祝你有美好的一天。

关于python - Google Ads API - "failed with status "PERMISSION_DENIED”- "User doesn' 没有访问客户的权限。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65675633/

相关文章:

python - 打印两个列表中都不存在的项目

python - 无法确定搁置数据库类型,whichdb 无法识别 gdb

python - 理解 python 中的逻辑(以艰难的方式学习 Python 的练习 27)

ruby-on-rails - 使用 Rails 跟踪转化时如何防止重复

python - 如何使用 Python shlex 解析 bash 数组?

python - QDataWidgetMapper-在pyqt中查找sql​​ite数据库行的索引

javascript - 与表单的提交按钮配合使用的 Google AdWords 转化跟踪

google-analytics - 在联系表单中显示 AdWords 广告系列

google-analytics - 我可以使用 GCLID 生成页面 View ,就好像它来自该 GCLID 的原始所有者一样

google-analytics - 通过包含/排除多个 pagePaths 的 API 批量创建 AdWords 受众