0

sorry before, maybe this is a stupid question.

I tried to make an application using Google Oauth2 using the steps from the tutorial: https://medium.com/@pablo127/google-api-authentication-with-oauth-2-on-the-example-of-gmail-a103c897fd98

Currently I have succeeded until I get access_token and refresh_token as below:

{
  "access_token": "*****",
  "expires_in": 3600,
  "refresh_token": "*****",
  "scope": "https://www.googleapis.com/auth/youtube",
  "token_type": "Bearer"
}

What I want to ask is, how to use the data on YoutubeAPI: https://developers.google.com/youtube/v3/docs/subscriptions/insert

Q1: So that I can subscribe or unsubscribe to certain channels through my application.

Q2: Also, how can I use "refresh_token" to get the next "access_token".

Thank you in advance.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
M. Pancadewa
  • 145
  • 11

1 Answers1

0

You can create a button that calls the subscriptionsInsert function. If you need information on how to create the button, you can refer to this SO question.

In the code provided, the channel that you subscribe to when the function is called is fixed to the channel with the ID: UC_x5XG1OV2P6uZZ5FSM9Ttw. To change this, you can try using Channels.list to get the channelId.

https://www.googleapis.com/youtube/v3/channels?key={YOUR_API_KEY}&forUsername={USER_NAME}&part=id

As for your second question, you can refresh an access token if you requested offline access to the scopes associated with the token.

  • If you use a Google API Client Library, the client object refreshes the access token as needed as long as you configure that object for
    offline access.
  • If you are not using a client library, you need to set the access_type HTTP query parameter to offline when redirecting the user to Google's OAuth 2.0 server. In that case, Google's authorization server returns a refresh token when you exchange an authorization code for an access token. Then, if the access token expires (or at any other time), you can use a refresh token to obtain a new access token.
droidBomb
  • 850
  • 5
  • 8
  • Sorry i am newbie for this, my question is how to implementation using PHP when i had "access token" using for "googleapis.com/youtube/v3/channels" ? – M. Pancadewa Nov 26 '18 at 20:17