0

im using the youtube api in python, i using this code :

   r = requests.get('https://www.googleapis.com/youtube/v3/videos')
   print(r.text)

and i get this output :

{
  "error": {
    "code": 403,
    "message": "The request is missing a valid API key.",
    "errors": [
      {
        "message": "The request is missing a valid API key.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}


Process finished with exit code 0

i already have my api key so my question is how do i add this api key to the GET request and make this work

1 Answer 1

1

The API key should be added as a GET parameter called key, like so:

r = requests.get('https://www.googleapis.com/youtube/v3/videos?key=YOUR_API_KEY&id=7lCDEYXw3mM&...')
print(r.text)

The documentation has a few more examples.

2
  • what is the id?
    – kfirwe
    Commented Aug 23, 2021 at 10:42
  • That's just an example. There are a few more required fields on this request, which are all listed in the reference documentation, but the key is the one you asked about. Commented Aug 23, 2021 at 10:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.