Google ads api for fetch audiences

35 views
Skip to first unread message

Shivam Kumar

unread,
Feb 6, 2024, 2:12:03 AM2/6/24
to Google Ads API and AdWords API Forum
I have created audience through python api(https://github.com/googleads/google-ads-python/blob/720b39e3538f65d1cc48ce1e92479154cfa2fc23/examples/remarketing/add_custom_audience.py) , and it was successful, I got the the resource name as a response. But when I am trying to fetch all audiences I am getting empty list. I am using following query to get audience list:

import argparse
import sys

from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException


def main(client, customer_id):
    # Get the GoogleAdsService client.
    googleads_service = client.get_service("GoogleAdsService")
    query = f"""
        SELECT
          audience.id,
          audience.name
        FROM audience
        """

    search_response = googleads_service.search(
        customer_id=customer_id, query=query
    )

    print(search_response)

    for res in search_response:
        print(res)


if __name__ == "__main__":
    googleads_client = GoogleAdsClient.load_from_storage(version="v15")

    parser = argparse.ArgumentParser(
        description="Updates the audience target restriction of a given ad "
        "group to bid only."
    )
    parser.add_argument(
        "-c",
        "--customer_id",
        type=str,
        required=True,
        help="The Google Ads customer ID.",
    )

    args = parser.parse_args()

    try:
        main(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}" 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) Thank You


Reply all
Reply to author
Forward
Message has been deleted
0 new messages