Skip to content

Latest commit

 

History

History
225 lines (138 loc) · 8.44 KB

youtube.md

File metadata and controls

225 lines (138 loc) · 8.44 KB

YouTube Account Setup

This guide walks through connecting your YouTube account to POSSE Party so it can upload videos on your behalf.

What POSSE Party Needs From You

  • Client ID for your Google Cloud OAuth client
  • Client Secret for that client
  • Access Token generated for the youtube.upload scope
  • Refresh Token paired with that access token so POSSE Party can renew it

All four values come from your Google Cloud project’s OAuth client and the token exchange step below.

How to Set Up Your Account

  1. Create a Google Cloud project and enable the YouTube Data API
  2. Configure OAuth consent and scopes
  3. Create an OAuth client with POSSE Party redirect URLs
  4. Add test users to the OAuth consent screen
  5. Authorize POSSE Party and exchange the code for tokens
  6. Add YouTube to POSSE Party

1. Create a Google Cloud Project and Enable the YouTube Data API

  1. Visit https://console.cloud.google.com and sign in with the Google account you use for YouTube. Check I agree… and click Agree and continue

Google Cloud welcome screen

  1. In the top bar, click Select a project.

Google Cloud terms of service prompt

  1. In the Select a project dialog, click New Project.

Google Cloud project selector

  1. Give the project a clear name (for example, POSSE Party YouTube) and click Create.

Google Cloud new project dialog

  1. Wait for creation to finish, then click Select project for the new project so it becomes the active one.

Google Cloud project creation in progress

  1. In the left sidebar, choose APIs & Services → Library.

Google Cloud dashboard with new project selected

  1. Search for YouTube Data API v3.

APIs & Services library in Google Cloud

  1. Click the YouTube Data API v3 result to open its details page.

Search results for YouTube Data API v3

  1. Click Enable to enable the API for your project.

YouTube Data API v3 details page

  1. After enabling, click Create credentials to start the OAuth setup.

YouTube Data API v3 enabled in Google Cloud

2. Configure OAuth Consent and Scopes

  1. When prompted for Credential type, select User data and click Next.

Credential type selection for user data

  1. On the OAuth consent screen step, fill out an app name and enter a user support email.

Credential type selection for user data

  1. Provide a developer contact email and click Save and continue.

OAuth consent screen app details

  1. On the Scopes step, search for the scope ending in /auth/youtube.upload.

OAuth consent screen support email section

  1. Check the box next to the YouTube upload scope and click Update.

Scope search for youtube.upload

  1. Back on the scopes list, click Save and continue to proceed.

Selected youtube.upload scope in OAuth scopes

3. Create an OAuth Client with POSSE Party Redirect URLs

  1. On the OAuth client ID step, choose Web application as the application type and give it a descriptive name.

Scopes step ready to save and continue

  1. Under Authorized redirect URIs, add two URLs and then click Create:
    • Your POSSE Party instance URL with the YouTube credential renewal path (e.g., https://example.posseparty.com/credential_renewals/youtube)
    • A localhost URL you will use once to obtain the initial tokens. (e.g., http://localhost:1234/callback)

OAuth client ID configuration for web application

  1. Under "Download your credentials", click Download.

OAuth client created with redirect URIs

  1. Open it in a text editor; it will contain a JSON object that looks like:
{
  "web": {
    "client_id": "myclient.apps.googleusercontent.com",
    "project_id": "posse-party-example-lol",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "myclientsecret",
    "redirect_uris": ["https://example.posseparty.com/credential_renewals/youtube"]
  }
}

Take note of the client_id and client_secret values.

  1. Click Done to exit the wizard.

Google Cloud credentials list with new OAuth client

4. Add Test Users to the OAuth Consent Screen

  1. In the left sidebar, click OAuth consent screen and then click Audience.

OAuth consent screen link in Google Cloud sidebar

  1. Scroll down to Test users and click Add users.

OAuth consent screen Audience section

  1. Add the email addresses for any Google accounts you plan to authorize with POSSE Party and click Save.

Add test users dialog

5. Authorize POSSE Party and Exchange the Code for Tokens

Next, you will perform a one-time OAuth flow using the localhost redirect URI to obtain an initial access token and refresh token.

  1. Copy the URL below and replace these two values:
    • CLIENT_ID with the client ID you noted earlier
    • CALLBACK_URL with the local callback URL you entered (we had suggested http://localhost:1234/callback)
https://accounts.google.com/o/oauth2/v2/auth?client_id=CLIENT_ID&redirect_uri=CALLBACK_URL&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload&access_type=offline&prompt=consent
  1. Open the URL in your browser and choose the Google account whose YouTube channel you want to connect.

Google account selection for OAuth

  1. Click the less prominent Continue link to proceed.

Google account selection screen

  1. Click Continue again.

Google OAuth warning screen with Continue option

  1. Your browser should redirect to your localhost URL. Don't be alarmed that it fails to connect! The value we need is in the URL itself.

Google OAuth consent confirmation

  1. Copy the URL from your browser's address bar and extract the code query parameter and take note of it

Browser cannot connect to localhost callback

  1. Open a terminal and run these commands, replacing the strings with the values you've noted in previous steps:
export CLIENT_ID="myclient.apps.googleusercontent.com"
export CALLBACK_URL="http://localhost:1234/callback"
export AUTH_CODE="the-code-you-just-copied"
export CLIENT_SECRET="myclientsecret"
  1. In the same terminal window, run the following curl command to exchange the OAuth code for access and refresh tokens
curl --request POST \
  --data "code=$AUTH_CODE" \
  --data "client_id=$CLIENT_ID" \
  --data "client_secret=$CLIENT_SECRET" \
  --data "redirect_uri=$CALLBACK_URL" \
  --data "grant_type=authorization_code" \
  https://oauth2.googleapis.com/token
  1. Google should return JSON similar to:
{
  "access_token": "yourtokenhere",
  "expires_in": 3599,
  "refresh_token": "yourrefreshtoken",
  "scope": "https://www.googleapis.com/auth/youtube.upload",
  "token_type": "Bearer",
  "refresh_token_expires_in": 604799
}

Copy both the access_token and refresh_token values for use in POSSE Party.

6. Add YouTube to POSSE Party

  1. In POSSE Party, go to Accounts and click Add Account. Give the account a label and select YouTube as the platform.

  2. Under Credentials for YouTube, fill:

    • Client ID
    • Client Secret
    • Access Token
    • Refresh Token

Browser address bar showing OAuth code

Once saved, POSSE Party will be able to create YouTube posts for crossposts that include exactly one video, and will use your refresh token to renew the access token as needed.