yt_oauth: Set up Authorization

yt_oauthR Documentation

Set up Authorization

Description

Simplified OAuth2 setup for YouTube Analytics API. This function will automatically detect the required scope based on your needs and provide helpful setup guidance.

Usage

yt_oauth(
  app_id = NULL,
  app_secret = NULL,
  scope = "analytics",
  token = ".httr-oauth",
  setup_guide = interactive(),
  ...
)

Arguments

app_id

Client ID from Google Cloud Console; required; no default

app_secret

Client secret from Google Cloud Console; required; no default

scope

Character. One of:

  • "analytics" - Basic analytics data (views, likes, etc.) - Default

  • "monetary" - Includes revenue and monetization data

  • "auto" - Automatically detect scope based on first API call

token

Path to file containing the token. Default is .httr-oauth in working directory.

setup_guide

Logical. Show setup guide for first-time users (default: TRUE for interactive sessions)

...

Additional arguments passed to oauth2.0_token

Details

The function looks for .httr-oauth in the working directory. If it doesn't find it, it expects an application ID and a secret. The function launches a browser to allow you to authorize the application.

Value

Sets the google_token option and saves .httr-oauth in working directory

References

https://developers.google.com/youtube/analytics/reference/

Examples

 ## Not run: 
   # Basic setup (will show setup guide first time)
   yt_oauth("your-client-id.apps.googleusercontent.com", "your-client-secret")

   # Setup with monetary scope for revenue data
   yt_oauth("your-client-id.apps.googleusercontent.com", "your-client-secret",
            scope = "monetary")

   # Skip setup guide
   yt_oauth("your-client-id.apps.googleusercontent.com", "your-client-secret",
            setup_guide = FALSE)

## End(Not run)

tubern documentation built on April 12, 2026, 5:07 p.m.