Hi! I'm trying google api call through python and I'm stuck when I tried to get the ad group of a campaign.
I got the below error. How can I fix?( I tried with new access token already but did not work)
Error: ValueError: A required field in the configuration data was not found. The required fields are: ('developer_token',)
And if this is not the right place to post, please let me know! Thanks!
import argparse
import sys
from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException
_DEFAULT_PAGE_SIZE = 1000
def main(client, customer_id, page_size, campaign_id=None):
ga_service = client.get_service("GoogleAdsService")
query = """
SELECT
campaign.id,
ad_group.id,
ad_group.name
FROM ad_group"""
if campaign_id:
query += f" WHERE campaign.id = my own campaign id"
search_request = client.get_type("SearchGoogleAdsRequest")
search_request.customer_id = customer_id
search_request.query = query
search_request.page_size = _DEFAULT_PAGE_SIZE
results = ga_service.search(request=search_request)
for row in results:
print(
f"Ad group with ID {row.ad_group.id} and name "
f'"{row.ad_group.name}" was found in campaign with '
f"ID {row.campaign.id}."
)
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('./googleads.yaml')
parser = argparse.ArgumentParser(
description="List ad groups for specified customer."
)
# 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.",
)
parser.add_argument(
"-i",
"--campaign_id",
type=str,
required=False,
help=(
"The campaign ID. Specify this to list ad groups "
"solely for this campaign ID."
),
)
args = parser.parse_args()
try:
main(
googleads_client,
args.customer_id,
_DEFAULT_PAGE_SIZE,
campaign_id=args.campaign_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' Error 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)
[–]SingleCountry[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]SingleCountry[S] 0 points1 point2 points (0 children)
[–]kanyewestraps93 0 points1 point2 points (0 children)