def __init__(self, credentials: MutableMapping[str, Any]): # `google-ads` library version `14.0.0` and higher requires an additional required parameter `use_proto_plus`. # More details can be found here: https://developers.google.com/google-ads/api/docs/client-libs/python/protobuf-messages credentials["use_proto_plus"] = True self.client = GoogleAdsClient.load_from_dict(credentials, version=API_VERSION) self.ga_service = self.client.get_service("GoogleAdsService")
def run(): os.makedirs(blob_directory, exist_ok=True) args = parse_arguments(sys.argv[1:]) print(banner) credentials = { **load_organization_auth(), **load_user_auth(), 'use_proto_plus': False, } client = GoogleAdsClient.load_from_dict(credentials) if 'no_dry_run' in args: if args.no_dry_run: print( "\033[31mYou are about to do a non-dry run, please type YOLO:" ) if input('> ') != 'YOLO': print('alright, that was close!') sys.exit(-1) else: print('*** THIS IS A DRY RUN ***') print('to perform a non-dry run, supply --no-dry-run') args.func(client, args) if 'no_dry_run' in args and not args.no_dry_run: print('*** THIS WAS A DRY RUN ***')
def _get_client(self) -> GoogleAdsClient: with NamedTemporaryFile("w", suffix=".json") as secrets_temp: self._get_config() self._update_config_with_secret(secrets_temp) try: client = GoogleAdsClient.load_from_dict(self.google_ads_config) return client except GoogleAuthError as e: self.log.error("Google Auth Error: %s", e) raise
def _get_customer_service(self) -> Resource: """Connects and authenticates with the Google Ads API using a service account""" with NamedTemporaryFile("w", suffix=".json") as secrets_temp: self._get_config() self._update_config_with_secret(secrets_temp) try: client = GoogleAdsClient.load_from_dict(self.google_ads_config) return client.get_service("CustomerService", version=self.api_version) except GoogleAuthError as e: self.log.error("Google Auth Error: %s", e) raise
def service(self): if not hasattr(self, "_service"): config_dict = { "developer_token": self.conn.developer_token, "client_id": self.conn.login, "client_secret": self.conn.password, "refresh_token": self.conn.refresh_token, # TODO: Refactor with use_proto_plus=False - for now, the code will work # See here for details : https://github.com/googleads/google-ads-python/issues/486 "use_proto_plus": True, } if self.conn.schema: config_dict["login_customer_id"] = self.conn.schema.replace("-", "") self._service = GoogleAdsClient.load_from_dict( config_dict=config_dict, version="v10", ).get_service("GoogleAdsService") return self._service
def __init__(self, credentials: Mapping[str, Any], customer_id: str): self.client = GoogleAdsClient.load_from_dict(credentials) self.customer_id = customer_id self.ga_service = self.client.get_service("GoogleAdsService")
def init_user_googleads_client(refresh_token: string) -> GoogleAdsClient: """Initiates a new user-based GoogleAds API client.""" api_config = _make_api_config_dict(refresh_token) ga_client = GoogleAdsClient.load_from_dict(api_config) return ga_client