Hikki
Hikki

Reputation: 524

What is "Your Access Token" in Youtube Data API and how to get it?

I got some code from youtube data API's try-it editor.

I have some curl code here, I have the API Key, but I don't know what [YOUR ACCESS TOKEN]is. I've been trying for the past two hours to find something, but couldn't get what I wanted.

I had an Oauth 2.0 client ID [742151xxxxxx.app.googleuserconsent.com] in google developers console.

I used it in place of [YOUR ACCESS TOKEN] but still got the authorization error.

Here is the cURL code:

curl \
  'https://www.googleapis.com/youtube/v3/playlistItems?part=id%2C%20snippet&playlistId=pbsF2UOcspaGQkAe1BCAR395sue-tp5r&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

Here is the error JSON:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}

Upvotes: 11

Views: 11066

Answers (1)

User1010
User1010

Reputation: 819

Clicking the question mark next to credentials in the try it editor provides some more information about the different authentication types offered, enter image description here

The google OAuth 2.0 Client Libraries offer a further explanation about the access tokens and how to obtain them including some pre-made libraries in a few languages.

https://developers.google.com/identity/protocols/oauth2#libraries

Upvotes: 4

Related Questions