错误:凭证'对象无属性'带有_subject'

发布于 2025-01-24 16:43:34 字数 1636 浏览 5 评论 0原文

我正在尝试使用服务帐户使用Google ADS API。
以下工作:

from google.ads.googleads.client import GoogleAdsClient
from google.oauth2.service_account import Credentials as ServiceAccountCreds

oauth2_client = ServiceAccountCreds.from_service_account_file(
    filename=key_file, subject=developer_account,
    scopes=["https://www.googleapis.com/auth/adwords"]
)
google_ads_client = GoogleAdsClient(login_customer_id=self.login_customer_id, credentials=oauth2_client,
                                    developer_token=self.developer_token)

self.ga_service = self.google_ads_client.get_service("GoogleAdsService", version="v9")
self.ga_serice.search_stream(customer_id=self.client_customer_id, query =  query)

我想对身份工作负载联合(w/o密钥)进行关注:

from google.auth import aws as google_auth_aws
from google.ads.googleads.client import GoogleAdsClient

credentials = google_auth_aws.Credentials.from_info(json_config_info)  # from workload identity federation
credentials = credentials.with_scopes(["https://www.googleapis.com/auth/adwords"])
credentials = credentials.with_subject(self.developer_account)
# Build the service object.
self.google_ads_client = GoogleAdsClient(login_customer_id=self.login_customer_id, credentials=credentials,
                                    developer_token=self.developer_token)

self.ga_service = self.google_ads_client.get_service("GoogleAdsService", version="v9")
self.ga_service.search_stream(customer_id =self.client_customer_id, query =  self.query)

这会引发错误: 错误:“凭据”对象没有_subject'。

I'm trying to use Google Ads API using service account.
The following works:

from google.ads.googleads.client import GoogleAdsClient
from google.oauth2.service_account import Credentials as ServiceAccountCreds

oauth2_client = ServiceAccountCreds.from_service_account_file(
    filename=key_file, subject=developer_account,
    scopes=["https://www.googleapis.com/auth/adwords"]
)
google_ads_client = GoogleAdsClient(login_customer_id=self.login_customer_id, credentials=oauth2_client,
                                    developer_token=self.developer_token)

self.ga_service = self.google_ads_client.get_service("GoogleAdsService", version="v9")
self.ga_serice.search_stream(customer_id=self.client_customer_id, query =  query)

I want to to do following with Identity Workload Federation(w/o key):

from google.auth import aws as google_auth_aws
from google.ads.googleads.client import GoogleAdsClient

credentials = google_auth_aws.Credentials.from_info(json_config_info)  # from workload identity federation
credentials = credentials.with_scopes(["https://www.googleapis.com/auth/adwords"])
credentials = credentials.with_subject(self.developer_account)
# Build the service object.
self.google_ads_client = GoogleAdsClient(login_customer_id=self.login_customer_id, credentials=credentials,
                                    developer_token=self.developer_token)

self.ga_service = self.google_ads_client.get_service("GoogleAdsService", version="v9")
self.ga_service.search_stream(customer_id =self.client_customer_id, query =  self.query)

Which throws error:
ERROR:'Credentials' object has no attribute 'with_subject'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文