views:

61

answers:

2

Hello, so i continue from this question http://stackoverflow.com/questions/3081097/youtube-get-youtube-title-imagedescription-like-facebook` i got this answer:

If you were given the video link http://www.youtube.com/watch?v=NWHfY_lvKIQ, you could get all the info about the video by using this link, http://gdata.youtube.com/feeds/api/videos/NWHfY_lvKIQ. The data returned contains all the information about the video, including title, description, and a thumbnail.

Now how can i get out the info about the video, with a script? I mean, how to do a script that displays description,thumbnail and title from http://gdata.youtube.com/feeds/api/videos/NWHfY_lvKIQ , do i need to download this first and then take out the information by opening in notepad, but thats not how i want it, i want it to show / echo through a script, the description+thumbnail+title, if you understand me correctly, just like what you do when you enter a link in facebook "what are you doing". Now i only want to show you for this video: http://gdata.youtube.com/feeds/api/videos/NWHfY_lvKIQ, just so i can learn to do the rest

thank you

A: 

You need a callback JSON. If you only want to get a video by the code (ie. NWHfY_lvKIQ) Use this:

http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&max-results=1&q=NWHfY_lvKIQ&callback=cbk

Important parts:

q=... - the query(the video code)

callback=... - the function that you want to call after the string is loaded.

Then put it inside a script tag

<script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos?v=2&amp;alt=jsonc&amp;max-results=1&amp;q=NWHfY_lvKIQ&amp;callback=cbk"&gt;&lt;/script&gt;

When this loads, it calls the function cbk and transfers its data.

digitalFresh
but how do i echo out it then to my page? like should i use $_GET["description"] ?? no?
Karem
Don't you want javascript? You use the callback function to display the data.
digitalFresh
+3  A: 

If you can use jquery, this is what I use to get the title, description, and url. If you can't use jquery, you can use some other ajax call, or the callback recommended by digitalFresh

$.get('http://gdata.youtube.com/feeds/api/videos/NWHfY_lvKIQ?v=2&amp;alt=json', function(data) {
        var title = data.entry.title.$t;
        var description = data.entry.media$group.media$description.$t;
        var thumbnail = data.entry.media$group.media$thumbnail[0].url; // URL of the image

        // Use these variables somewhere
});
Quantumgeek