 |
| Author | Post |
|---|
Admin Administrator

| Joined: | Mon Mar 5th, 2007 |
| Location: | Chicago, Illinois USA |
| Posts: | 341 |
| Status: |
Offline
|
| Mana: |     |
|
Posted: Thu Dec 27th, 2007 08:11 pm |
|
YouTube API Developers "Tips & Tricks"
Share your pearls of wisdom about the API with your fellow developers! Do it for the karma (and the glory).
There's no set format, but please try to make it readable with a clear title.
==============================================================================
URL Tricks
Normal YouTube URL for embedding a video:
<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/VIDEO_ID"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/VIDEO_ID" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
</object>
Autoplaying your video:
<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/VIDEO_ID&autoplay=1"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/VIDEO_ID&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
</object>
Removing related videos from the flash player
<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/VIDEO_ID&rel=0"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/VIDEO_ID&rel=0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
</object>
If you want to change the size of the video, you must change the size of the object AND the embed statement.
Retrieving XML data in an array format in PHP
XML data can be cleanly returned in a Class Object array format using a PHP extension called SimpleXML.
Using it is very easy. First, you must get the XML. This is done very easily with file_get_contents().
Example:
My example will show how to get the Video ID, Title, and Thumbnail URL of a video on YouTube
$xml_url = "http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=DEV_ID&video_id=VID_ID";
$data = file_get_contents($xml_url);
// I use file_get_contents because it works with HTTP wrappers and returns everything as a large string. It's also easier to use than fopen.
$xml_array = new SimpleXMLElement($data);
// SimpleXMLElement is a PHP extension that does not need to be activated in the page you are writing. The PHP installation should come with it activated.
// It will return the data in this format:
//
// $data->video_details->ATTRIBUTE_NAME
//
// For example, we are getting the title, id, and thumbnail, so we'd do this:
$title = $data->video_details->title;
$id = $data->video_details->id;
$thumb = $data->video_details->thumbnail_url;
// And that's it!
//
// If you are confused on how the XML is returned into the array, you can dump the Class Object to the screen using this method:
//
// echo "<pre>";
// print_r($xml_array);
// echo "</pre>";
//
// That will return a cleanly formatted dump of the variable, which you can use as a reference to get your variables.
For more information on SimpleXML, visit the PHP function on php.net directly at http://us.php.net/manual/en/ref.simplexml.php
____________________ Yougle - The number one rated Movie, Video & Film search engine to ever emerge!
|
 Current time is 01:38 pm | |
|
|
 |
|