[Python] Error Creating Job in YouTube Reporting API

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm following the API referenced here but nothing I am doing seems to be working. Below is my code and the error message I am getting

    import requests
    access_token = 'MY_ACCESS_TOKEN'

    headers = {
    "content-type": "application/x-www-form-urlencoded",
    "Authorization": f"Bearer {access_token}",
    }
    url = "https://youtubereporting.googleapis.com/v1/jobs"
    data = {
    "reportTypeId": "channel_basic_a2",
    "name": "my_job",
    }
    response = requests.post(url, headers=headers, data=data)
    # Also tried
    # response = requests.post(url, headers=headers, params=data)
    assert response.status_code == 200, f"{response.status_code} {response.text}"
    print(response.text)


    Below is the error message I am getting

    "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"reportTypeId\": Cannot bind query parameter. Field 'reportTypeId' could not be found in request message.\nInvalid JSON payload received. Unknown name \"name\": Cannot bind query parameter. Field 'name' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
    {
    "@type": "type.googleapis.com/google.rpc.BadRequest",
    "fieldViolations": [
    {
    "description": "Invalid JSON payload received. Unknown name \"reportTypeId\": Cannot bind query parameter. Field 'reportTypeId' could not be found in request message."
    },
    {
    "description": "Invalid JSON payload received. Unknown name \"name\": Cannot bind query parameter. Field 'name' could not be found in request message."
    }
    ]
    }
    ]
    }

    Continue reading...

Compartilhe esta Página