[Python] Local Services Ads API Python - No Data

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I do the oauth flow and then run the following code, but I'm getting no data; I've confirmed the manager_customer_id does in fact exist. Any suggestions of why? Thanks!

    scopes = ["https://www.googleapis.com/auth/adwords"]

    # Create an instance of InstalledAppFlow
    flow = InstalledAppFlow.from_client_config(
    {
    "web": {
    "client_id": client_id,
    "client_secret": client_secret,
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token"
    }
    },
    scopes=scopes
    )

    # Choose a consistent port number for the OAuth callback
    # Make sure this port is the same as the one set in your Google Cloud Console redirect URI
    #credentials = flow.run_local_server(port=0)

    print(f"Running local server for authentication on port {consistent_port}...")

    # Run the flow to get the credentials
    credentials = flow.run_local_server(port=consistent_port)

    print("Authentication successful. Obtained credentials.")

    # Use credentials to create a session
    session = requests.Session()
    session.headers.update({'Authorization': f'Bearer {credentials.token}'})

    print("Session created. Preparing API request...")

    # Your API request code goes here
    url = "https://localservices.googleapis.com/v1/accountReports:search"


    params = {
    "query": "manager_customer_id:xxxxx",
    # "startDate.month": "12",
    # "startDate.day": "1",
    # "startDate.year": "2023",
    # "endDate.month": "12",
    # "endDate.day": "31",
    # "endDate.year": "2023",
    # "pageSize": "500",
    }

    # Send the GET request using the OAuth session
    response = session.get(url, params=params)


    # Check if the request was successful
    if response.status_code == 200:
    print("Successfully received API response.")
    data = response.json()
    print("Data:", data)
    else:
    print("Failed to retrieve data. Status code:", response.status_code)
    print("Response:", response.text)

    Continue reading...

Compartilhe esta Página