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

1

10

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"
 }
}
Cithara answered 21/3, 2020 at 19:21 Comment(1)
I have the same problem. How to get the access token?Vespers
M
4

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

Movable answered 21/3, 2020 at 20:1 Comment(2)
I need the access token to run the curl command in the terminal. That link only has libraries for specific languages like Java, PHP, Go...Vespers
@NamLêQuý Depending on what authentication method you are looking for take a look at some of examples on the side under "access to googles APIs", these have examples for HTTP/REST direct calls though are not recommended by Google, developers.google.com/identity/protocols/oauth2/…Movable

© 2022 - 2024 — McMap. All rights reserved.