Part 3 - Import the Google Ads Client Library

Stay organized with collections Save and categorize content based on your preferences.

In this part we'll show how to import the Google Ads client library and initialize a Google Ads client so that it can make requests to the API.

Part 3.1 - Insert necessary import statements

To import the Google Ads client into the script, add this statement to the top of the file:

3.1.0: Import the Google Ads API Client Library
# imports the Google Ads client from the google-ads package
from google.ads.googleads.client import GoogleAdsClient
      

Part 3.2 - Define your client customer ID as a global variable

Where appropriate depending on the language you're using, add the client customer ID of the test account you're using as a global variable in the script:

3.2.0: Insert your Client Customer ID
# Set your test CID
_CUSTOMER_ID = "1234567890"
      

Part 3.3 - Initialize a Google Ads client

As with the AdWords API client library, we'll initialize a Google Ads API client using credentials stored in the local configuration file. Add the highlighted line below to the bottom of the script:

3.3.0: Initialize a Google Ads API Client
if __name__ == "__main__":
    # Initialize the client object.
    # By default, it will read the config file from the Home Directory.
    adwords_client = adwords.AdWordsClient.LoadFromStorage()
    # Add the googleads_client here alongside the adwords_client
    googleads_client = GoogleAdsClient.load_from_storage()
    budget_id = _create_campaign_budget(adwords_client)
    campaign_id = _create_campaign(adwords_client, budget_id)
    ad_group_id = _create_ad_group(adwords_client, campaign_id)
    _create_text_ads(adwords_client, ad_group_id)
    _create_keywords(adwords_client, ad_group_id, KEYWORDS_TO_ADD)