0

so i continue from this question YouTube: get youtube title+ image+description 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

2 Answers 2

3

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&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
});
Sign up to request clarification or add additional context in comments.

Comments

0

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&alt=jsonc&max-results=1&q=NWHfY_lvKIQ&callback=cbk"></script>

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

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.