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_global_googleads_client(): global GOOGLEADS_CLIENT if GOOGLEADS_CLIENT: return GOOGLEADS_CLIENT else: setup.set_api_configs() GOOGLEADS_CLIENT = GoogleAdsClient.load_from_storage( CONFIG_PATH / 'google-ads.yaml') return GOOGLEADS_CLIENT
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
invitation.access_role = client.enums.AccessRoleEnum[access_role].value response = service.mutate_customer_user_access_invitation( customer_id=customer_id, operation=invitation_operation) print("Customer user access invitation was sent for " f"customer ID: '{customer_id}', " f"email address {email_address}, and " f"access role {access_role}. The invitation resource name is: " f"{response.result.resource_name}") # [END invite_user_with_access_role] if __name__ == "__main__": # GoogleAdsClient will read the google-ads.yaml configuration file in the # home directory if none is specified. googleads_client = GoogleAdsClient.load_from_storage(version="v8") parser = argparse.ArgumentParser(description=( "Sends an invitation email to a user to manage a customer " "account with a desired access role.")) # The following argument(s) should be provided to run the example. parser.add_argument( "-c", "--customer_id", type=str, required=True, help="The Google Ads customer ID.", ) parser.add_argument( "-e", "--email_address",
if __name__ == '__main__': parser = argparse.ArgumentParser( description='Check status of customer match list jobs in Google Ads.') parser.add_argument('--config_file', default=CONFIG_PATH, help='Configuration file for Google Ads API access.') parser.add_argument('--customer_id', required=True, help='The customer ID for which to add the user list.') parser.add_argument('--job_resource_name', required=True, help='Offline user data job resource name to check.') parser.add_argument('--user_list_resource_name', required=True, help='User list resource name.') args = parser.parse_args() google_ads_client = GoogleAdsClient.load_from_storage(args.config_file) try: check_job_status(google_ads_client, args.customer_id, args.job_resource_name, args.user_list_resource_name) except GoogleAdsException as ex: print(f'Request with ID "{ex.request_id}" failed with status ' f'"{ex.error.code().name}" and includes the following errors:') for single_error in ex.failure.errors: print(f'\tError with message "{single_error.message}".') if single_error.location: for field_path_element in single_error.location.field_path_elements: print(f'\t\tOn field: {field_path_element.field_name}')
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")
parser = argparse.ArgumentParser( description="This analyzer will display the account info " "according to the input." ) # process argument(s) parser.add_argument( "-c", "--customer_id", type=str, required=False, help="The Google Ads customer ID.", ) args = parser.parse_args() try: googleads_client = GoogleAdsClient.load_from_storage() account_hierarchy_module(googleads_client, args.customer_id) get_users_module(googleads_client, args.customer_id) except GoogleAdsException as ex: print( f'Request with ID "{ex.request_id}" failed with status ' f'"{ex.error.code().name}" ' ) print(f"And includes the following errors:") for error in ex.failure.errors: print(f'\tError with message "{error.message}".') if error.location: for field_path_element in error.location.field_path_elements: print(f"\t\tOn field: {field_path_element.field_name}") sys.exit(1)
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