KingSchwifty
KingSchwifty

Reputation: 36

YouTube API Using A Refresh Token In Curl Request

so just using the curl request: https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel=={channel id}&start-date=2016-10-01&end-date=2016-10-10&metrics=views&access_token={accesstoken}

I was wondering how do I use the refresh token instead of the access token? I'm using this json request through a google sheets script so if possible it has to be all in the url, and no JS or PHP.

Any help will be greatly appreciated.

Upvotes: 0

Views: 1241

Answers (1)

Yshanae
Yshanae

Reputation: 119

You cannot use the refresh token directly in your request, so you will need to do a curl request to get an access token from your refresh token. Then you can use the access token in your request.

The request to get the access token will look like that:

https://www.googleapis.com/oauth2/v4/token?grant_type=refresh_token&refresh_token={your_refresh_token}&client_id={your_client_id}&client_secret={your_client_secret}

And the response will follow this format:

{
  "access_token" : "ya29.AHES6ZSuY8f6WFLswSv0HELP2J4cCvFSj-8GiZM0Pr6cgXU",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "refresh_token" : "1/551G1yXUqgkDGnkfFk6ZbjMLMDIMxo3JFc8lY8CAR-Q"
}

If you need, there is some information about using a refresh token to get an access token here, under the header "Using an access token".

Hope this help!

Upvotes: 1

Related Questions