How Can I retrive data from Google Ads API
(1) In the area I am now, Google website is not visitable because of the Great Firewall. But I am using Clash for Windows and I could access and visit Google website. It works well on my browser.
(2)I am testing Google Ads API with simple function in Python like the following through Jupyter Notebook which is installed on my Windows 10 laptop:
import logging logging.basicConfig(level=logging.INFO) from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.errors import GoogleAdsException # Define the main function def main(client, customer_id): ga_service = client.get_service("GoogleAdsService") query = """ SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id """ # Issues a search request using streaming. stream = ga_service.search_stream(customer_id=customer_id, query=query) # Iterate through the results and print them for batch in stream: for row in batch.results: print( f"Campaign with ID {row.campaign.id} and name " f"{row.campaign.name}" ) # Load Google Ads client from storage # Replace "PATH/TO/YOUR/google-ads.yaml" with the actual path to your file googleads_client = GoogleAdsClient.load_from_storage(path=r"C:\Users\tomxi\google-ads.yaml", version="v15") # Get customer ID from user input (optional) # Replace with your desired method of obtaining the customer ID customer_id = "xxxxxxxxxx" # Call the main function try: main(googleads_client, customer_id) 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 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)
(3)I got the error:
[TransportError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by SSLError(SSLEOFError(8, '\[SSL: UNEXPECTED_EOF_WHILE_READING\] EOF occurred in violation of protocol (_ssl.c:1006)')))][1]
(4)I guess the Google Ads API employs some route or something else which is not used or controlled by the Clash for Window on my laptop. I am not sure how to check and change it. Please help me.