Giter Site home page Giter Site logo

Comments (2)

BenRKarl avatar BenRKarl commented on July 24, 2024

Hi @shivam-2002 thanks for pointing this out. This looks like a typo, there is indeed no example called get_ad_groups. I'll remove that line, meanwhile if you want to retrieve ad groups see the ad_group resource.

To be more specific, if you want to get all the ad groups for an account, you can follow the get_campaigns example, but use the below query instead:

SELECT
  ad_group.id,
  ad_group.name
FROM ad_group

from google-ads-python.

shivam-2002 avatar shivam-2002 commented on July 24, 2024

Than You Ben for your kind attention, I already have written the code for above. If you want you can attach a new file get_ad_groups.py.

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
          ad_group.id,
          ad_group.name
        FROM ad_group
        """

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

    for res in search_response:
        print(res)


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="v15")

    parser = argparse.ArgumentParser(
        description="Updates the audience target restriction of a given ad "
        "group to bid only."
    )
    # 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.",
    )

    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)
        
        
        

Hi @shivam-2002 thanks for pointing this out. This looks like a typo, there is indeed no example called get_ad_groups. I'll remove that line, meanwhile if you want to retrieve ad groups see the ad_group resource.

To be more specific, if you want to get all the ad groups for an account, you can follow the get_campaigns example, but use the below query instead:

SELECT
  ad_group.id,
  ad_group.name
FROM ad_group

from google-ads-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.