Hello - I am using Python script to pull Campaign Information . I generated the refresh token via Google Oauth2 Playground and use that in the script to generate access token when the script is run. Below is the code , I use to hit the api .
import requests
def fetch_campaigns(customer_id, access_token, developer_token):
url = f"
https://googleads.googleapis.com/v18/customers/{customer_id}/googleAds:search"
headers = {
"Authorization": f"Bearer {access_token}",
"developer-token": developer_token,
"Content-Type": "application/json"
}
query = {
"query": """
SELECT
customer.id,
customer.manager,
customer.resource_name,
customer.status,
customer.test_account,
campaign.name,
campaign.id FROM
campaign
"""
}
try:
response =
requests.post(url, json=query, headers=headers)
print("Status Code:", response.status_code)
print("Headers:", response.headers)
print("Response Body:", response.json())
# Raise an error for bad status codes
response.raise_for_status()
# Return the JSON response
return response.json()
except requests.exceptions.RequestException as e:
print("Error making request:", e)
return None
# Example usage
customer_id = "INSERT_CUSTOMER_ID_HERE"
access_token = "INSERT_ACCESS_TOKEN_HERE"
developer_token = "INSERT_DEVELOPER_TOKEN_HERE"
result = fetch_campaigns(customer_id, access_token, developer_token)
if result:
print("Campaigns:", result).
I get the status code '200' . But the response is missing the "results" field. We have a master customer account and under we have multiple accounts for each department. So do I need to provide the account id as well to get the results ? If yes , the how ? I am not seeing any resources mentioning that step. Kindly help me out on this.