views:

445

answers:

1

Hi,

In my Rails app I want users to be able to input video links from YouTube. I want to be able to display the YouTube icon for that link.

How can I do that?

Thanks,

Tam

+2  A: 

You can use the Youtube data API to retrieve data about a single video. So pull the video id from the user's link, then make a request to the API to retrieve the thumbnail URL.

More information can be found in the documentation here:

http://code.google.com/apis/youtube/2.0/developers%5Fguide%5Fprotocol%5Fvideo%5Fentries.html

This is the link to call that returns an atom feed for a single video that includes the thumbnail URL:

http://gdata.youtube.com/feeds/api/videos/videoid

Travis
This solution is correct. However, to only display image it's easier just to user direct link: http://img.youtube.com/vi/[VIDEO_ID]/1.jpg Thanks
Tam
That's true, although it's always possible they change the structure of that link, in which case your images would break. Still, that's probably pretty unlikely.
Travis