Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
 }
}
like image 230
Hikki Avatar asked Mar 21 '20 19:03

Hikki


People also ask

What is an access token for YouTube?

The access token lets the application authorize requests on the user's behalf, and the refresh token lets the application retrieve a new access token when the original access token expires.


1 Answers

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

like image 172
User1010 Avatar answered Oct 29 '22 08:10

User1010