Ruby Quickstart

  • This guide walks you through creating a simple Ruby command-line application that interacts with the YouTube Data API in approximately five minutes.

  • The application retrieves and displays basic information about the GoogleDevelopers YouTube channel using the YouTube Data API.

  • The process involves enabling the YouTube Data API, installing the Google Client Library for Ruby, and setting up and running the provided sample code quickstart.rb.

  • The first time you run the application, you'll be prompted to authorize access to your Google account, which will be saved for future executions.

  • The sample code showcases how to request and print the channel's ID, title, and view count using the channels.list API method.

Complete the steps described in the rest of this page, and in about five minutes you'll have a simple Ruby command-line application that makes requests to the YouTube Data API.

The sample code used in this guide retrieves the channel resource for the GoogleDevelopers YouTube channel and prints some basic information from that resource.

Prerequisites

To run this quickstart, you'll need:

  • Ruby 2.0 or greater.
  • Access to the internet and a web browser.
  • A Google account.

Step 1: Turn on the YouTube Data API

  1. Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.

  2. On the Create credentials page, click the Cancel button.

  3. At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.

  4. Select the Credentials tab, click the Create credentials button and select OAuth client ID.

  5. Select the application type Other, enter the name "YouTube Data API Quickstart", and click the Create button.

  6. Click OK to dismiss the resulting dialog.

  7. Click the (Download JSON) button to the right of the client ID.

  8. Move the downloaded file to your working directory and rename it client_secret.json.

Step 2: Install the Google Client Library

Run the following command to install the library:

gem install google-api-client

See the library's installation page for the alternative installation options.

Step 3: Set up the sample

Create a file named quickstart.rb in your working directory and copy in the following code:

# Sample Ruby code for user authorization

require 'rubygems'
gem 'google-api-client', '>0.7'
require 'google/apis'
require 'google/apis/youtube_v3'
require