kfirwe
kfirwe

Reputation: 13

python yt api "The request is missing a valid API key."

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

Upvotes: 0

Views: 852

Answers (1)

Wander Nauta
Wander Nauta

Reputation: 19695

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.

Upvotes: 1

Related Questions