3
votes

Bonjour !

I have seen a lot of similar questions, but can't figure out why none of them brings a clear answer.

I'm trying to use the google-api-client gem to connect to youtube data api to retrieve a thumbnail image from a youtube video link. I assume I don't need to deal with that (obscure to me) oAuth authentication.

  • First step : I create the project with google api console, authorizing the Youtube Data API. In the "API Access" tab, I select "Create a client ID..." with option "Service Account".

It gave me a client ID, email address and public key fingerprints.

  • Second : I create my ruby script using the google-api-client gem. I just copy/paste the example in the documentation that is :

    require 'google/api_client'

    client = Google::APIClient.new

From my client object I thought I could directly call client.execute() to get my atom feed with all my video information. But I just have an idea how to do it.

Maybe I also have to get oAuth authorization ? To get the token ?

What am I missing ?

Many thanks for your contributions.

1

1 Answers

7
votes

That wasn't so hard, I found out how to do it.

You don't need to deal with oAuth authentication in that case. You will need to generate a server API Key and send it on each request.

The following snippet will help retrieving all information about a video the API provides.

require 'google/api_client'
require 'json'

client = Google::APIClient.new

youtube = client.discovered_api('youtube', 'v3')

client.authorization = nil

result = client.execute :key => "<YOUR_SERVER_API_KEY>", :api_method => youtube.videos.list, :parameters => {:id => '<YOUR_VIDEO_ID>', :part => 'snippet'}

result = JSON.parse(result.data.to_json)