dimanche 28 juin 2015

Why does it get "undefined method `videoId'" sometimes?

I'm trying to load the search result of Youtube with using its API.
It looks working fine so far but it sometimes get this error

ActionView::Template::Error (undefined method `videoId' for #<Google::APIClient::Schema::Youtube::V3::ResourceId:0x000000072afcb8>):

I'm just wondering if YouTube won't provide its videoId sometimes under some particular situation?

How can I avoid this problem?

CONTROLLER

. 
.
.
@search_response = client.execute!(
  :api_method => youtube.search.list,
  :parameters => {
    :part => 'snippet',
    :q => 'cat',
    :maxResults => 10,
    :order => 'date',
    :pageToken => pageToken
  }
)
.
.
.

VIEW

<% @search_response.data.items.each do |video| %>
    ID: <%= video.id.videoId %><br />
    Title: <%= video.snippet.title %><br />
    Description: <%= video.snippet.description %><br />
    <img src="<%= video.snippet.thumbnails.high.url %>" with="480" height="360"><br />
    <br />
    <br />
<% end %>


<%= debug @search_response.data.items %>

Aucun commentaire:

Enregistrer un commentaire