1818import argparse
1919import sys
2020
21- import google .ads .google_ads .client
21+ from google .ads .google_ads .client import GoogleAdsClient
22+ from google .ads .google_ads .errors import GoogleAdsException
2223
2324
24- _DEFAULT_PAGE_SIZE = 1000
25-
26-
27- def main (client , customer_id , page_size ):
25+ def main (client , customer_id ):
2826 ga_service = client .get_service ('GoogleAdsService' , version = 'v3' )
2927
3028 query = (
@@ -37,47 +35,45 @@ def main(client, customer_id, page_size):
3735 'billing_setup.payments_account_info.secondary_payments_profile_id '
3836 'FROM billing_setup' )
3937
40- results = ga_service .search (customer_id , query = query , page_size = page_size )
38+ response = ga_service .search_stream (customer_id , query = query )
4139
4240 try :
4341 # Use the enum type to determine the enum name from the value.
44- billing_setup_status_enum = (
45- client .get_type ('BillingSetupStatusEnum' , version = 'v3' )
46- .BillingSetupStatus )
42+ billing_setup_status_enum = client .get_type (
43+ 'BillingSetupStatusEnum' , version = 'v3' ).BillingSetupStatus
4744
4845 print ('Found the following billing setup results:' )
49- for row in results :
50- billing_setup = row . billing_setup
51- payments_account_info = billing_setup . payments_account_info
52- print ( 'Billing setup with ID "%s", status "%s", '
53- 'payments_account "%s", payments_account_id "%s", '
54- 'payments_account_name "%s", payments_profile_id "%s", '
55- 'payments_profile_name "%s", '
56- ' secondary_payments_profile_id "%s".'
57- % ( billing_setup .id .value ,
58- billing_setup_status_enum .Name (billing_setup .status ),
59- billing_setup .payments_account .value ,
60- payments_account_info .payments_account_id .value ,
61- payments_account_info .payments_account_name .value ,
62- payments_account_info .payments_profile_id .value ,
63- payments_account_info .payments_profile_name .value ,
64- payments_account_info . secondary_payments_profile_id . value ) )
65- except google . ads . google_ads . errors . GoogleAdsException as ex :
66- print ('Request with ID "%s " failed with status "%s" and includes the '
67- 'following errors:' % ( ex .request_id , ex . error .code ().name ) )
46+ for batch in response :
47+ for row in batch . results :
48+ billing_setup = row . billing_setup
49+ pai = billing_setup . payments_account_info
50+ if pai . secondary_payments_profile_id . value :
51+ secondary_payments_profile_id = pai . secondary_payments_profile_id . value
52+ else :
53+ secondary_payments_profile_id = "None"
54+ print ( f'Billing setup with ID { billing_setup .id .value } , '
55+ f'status " { billing_setup_status_enum .Name (billing_setup .status )} ", '
56+ f'payments_account " { billing_setup .payments_account .value } " '
57+ f'payments_account_id { pai .payments_account_id .value } , '
58+ f'payments_account_name " { pai .payments_account_name .value } ", '
59+ f'payments_profile_id { pai .payments_profile_id .value } , '
60+ f'payments_profile_name " { pai .payments_profile_name .value } ", '
61+ f' secondary_payments_profile_id { secondary_payments_profile_id } .' )
62+ except GoogleAdsException as ex :
63+ print (f 'Request with ID "{ ex . request_id } " failed with status '
64+ f'" { ex .error .code ().name } " and includes the following errors:' )
6865 for error in ex .failure .errors :
69- print ('\t Error with message "%s".' % error .message )
66+ print (f '\t Error with message "{ error .message } ".' )
7067 if error .location :
7168 for field_path_element in error .location .field_path_elements :
72- print ('\t \t On field: %s' % field_path_element .field_name )
69+ print (f '\t \t On field: { field_path_element .field_name } ' )
7370 sys .exit (1 )
7471
7572
7673if __name__ == '__main__' :
7774 # GoogleAdsClient will read the google-ads.yaml configuration file in the
7875 # home directory if none is specified.
79- google_ads_client = (google .ads .google_ads .client .GoogleAdsClient
80- .load_from_storage ())
76+ google_ads_client = GoogleAdsClient .load_from_storage ()
8177
8278 parser = argparse .ArgumentParser (
8379 description = 'Lists all billing setup objects for specified customer.' )
@@ -86,4 +82,4 @@ def main(client, customer_id, page_size):
8682 required = True , help = 'The Google Ads customer ID.' )
8783 args = parser .parse_args ()
8884
89- main (google_ads_client , args .customer_id , _DEFAULT_PAGE_SIZE )
85+ main (google_ads_client , args .customer_id )
0 commit comments