Integrations

YouTube Integration with GPAL.YouTube

Connecting with Google OAuth

GPAL.YouTube uses OAuth 2.0 authentication, not a simple API key. You create a project in the Google Cloud Console, enable the YouTube Data API, and obtain a client ID and secret. Build credentials with those values and the YouTube upload scope -- you will need to go through one-time browser consent and save the refresh token so subsequent runs can skip that step. Upload is the terminal call: it streams the file and returns the video ID, a short shareable URL, and the upload status. Privacy can be set to public, private, or unlisted.

ICredentials ytCreds = GPAL.Credentials

.WithService(CredentialServiceType.Google)

.WithServiceKey("your-client-id:your-client-secret")

.WithScope(OAuthScope.YouTube_Upload)

.WithRefreshToken("your-refresh-token")

.ToGPALObject();


YouTubeUploadResult result = GPAL.YouTube

.WithCredentials(ytCreds)

.WithTitle("My First Upload")

.WithPrivacy(YouTubePrivacy.Unlisted)

.Upload((GPALFile)"C:\videos\myvideo.mp4");


Console.WriteLine(result.Url);

Playlists

Playlists are created with the same fluent pattern used for uploads -- set a title, description, and privacy, then call CreatePlaylist instead of Upload. The returned playlist ID slots directly into an upload chain via WithPlaylist, so each video is added to the playlist as part of the upload call itself. To add a batch of already-uploaded videos to a playlist, pass them through WithVideos and call AddToPlaylist.

// Create a playlist

var playlist = GPAL.YouTube

.WithCredentials(ytCreds)

.WithTitle("GPAL Tutorials")

.WithDescription("Learn GPAL through short focused videos.")

.WithPrivacy(YouTubePrivacy.Public)

.CreatePlaylist();


// Upload and add to the playlist in one chain

var result = GPAL.YouTube

.WithCredentials(ytCreds)

.WithTitle("Introduction to GPAL")

.WithPlaylist(playlist.PlaylistId)

.Upload((GPALFile)"C:videosintro.mp4");

// the video is added to the playlist as part of Upload


// Add a batch of existing upload results to a playlist

GPAL.YouTube

.WithCredentials(ytCreds)

.WithVideos(batchResults)

.AddToPlaylist(playlist.PlaylistId);

NOTE

WithPlaylist stores the target playlist ID on the builder. No API call is made at that point -- the add-to-playlist request fires inside Upload after the video ID is confirmed. This means the pattern reads as a single intent: upload this file and land it in that playlist.

Searching Your Channel and Retrieving Video Info

To search your own channel, set one or more terms and call GetResults with an out variable. The grid form iterates every row using column zero as the search term and deduplicates results across all terms automatically. For a known video ID, use the single-result overload, which retrieves full metadata including tags and published timestamp -- fields the search endpoint does not return.

// Search your channel by keyword

GPAL.YouTube

.WithCredentials(ytCreds)

.WithSearchTerms("getting started")

.GetResults(out List<YouTubeVideoInfo> found);


// Supply terms from a grid

// results across all terms are deduplicated by video ID

GPAL.YouTube

.WithCredentials(ytCreds)

.WithSearchTerms(keywordsGrid)

.GetResults(out List<YouTubeVideoInfo> allResults);


// Full metadata by video ID (includes tags and published date)

GPAL.YouTube

.WithCredentials(ytCreds)

.WithVideoId("abc123xyz")

.GetResults(out YouTubeVideoInfo info);


Console.WriteLine($"{info.Title} -- {info.PublishedAt:d}");

WARNING

Upload your videos first to collect YouTubeUploadResult objects, then start a new chain with WithVideos, WaitForProcessing, and ScheduleAt. ScheduleAt fires a background thread and returns immediately -- in a console app call WaitForCompletion on the return value to keep the process alive until all videos are scheduled.

💬 Ask GPAL