witnessmenow / arduino-youtube-api

A wrapper around the youtube api for arduino
MIT License
141 stars 48 forks source link

Added OAuth2 support and getMyRecentSubscribers #6

Open marcfon opened 7 years ago

marcfon commented 7 years ago

This current pull requests breaks backwards compatibility. Let me what you think is the best way to fix this.

I've implemented OAuth2 support because it's needed te access certain information like the most recent subscribers to a YouTube channel.

marcfon commented 7 years ago

These are the steps I've used to get the authentication credentials:

  1. Create Client ID and Client Secret (use “other app") - see https://developers.google.com/youtube/v3/guides/auth/devices
  2. Get your device code (= the user_code in the return parameters) - curl -d "client_id=YOUR_CLIENT_ID_FROM_STEP_1&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.readonly" https://accounts.google.com/o/oauth2/device/code
  3. Copy the user_code value obtained in step 2
  4. Grant access via https://www.google.com/device using the user_code
  5. Get access token & refresh token - curl -d "client_id=YOUR_CLIENT_ID_FROM_STEP_1&client_secret=YOUR_CLIENT_SECRET_FROM_STEP_1&code=YOUR_DEVICE_CODE_FROM_STEP_2&grant_type=http://oauth.net/grant_type/device/1.0" -H "Content-Type: application/x-www-form-urlencoded" https://www.googleapis.com/oauth2/v4/token
  6. Test the access token - open this url in your browser https://www.googleapis.com/youtube/v3/channels?access_token=YOUR_ACCESS_TOKEN_FROM_STEP_5&part=snippet&mine=true
  7. Optional: command to manually refresh the access token (this is build into the lib) - curl -d "client_id=YOUR_CLIENT_ID_FROM_STEP_1&client_secret=YOUR_CLIENT_SECRET_FROM_STEP_1&refresh_token=YOUR_REFRESH_TOKEN_FROM_STEP_5&grant_type=refresh_token" -H "Content-Type: application/x-www-form-urlencoded" https://www.googleapis.com/oauth2/v4/token