This module requires PHP5, due to usage of SimpleXML.

Included in the package are two modules:

youtube_api.module
This module provides a set of functions acting as a bridge to the YouTube public API. Do not use this on a production site unless you're capable of assessing the quality of the code, and comfortable fixing any problems which might pop up.
youtube_feed.module
Provides feedapi integration with youtube feeds

An up to date function reference can be found http://atendesigngroup.com/youtube_api/index.html

I'm working on more complete documention, but for now to test run the API, just create a custom module with the following code. It will give an overview of a few of the features this module provides:

<?php
function my_module_menu($may_cache) {
  if (
$may_cache) {
   
$items[] = array(
     
'path' => 'my_module_youtube',
     
'title' => t('YouTube API Tester'),
     
'description' => 'Test YouTube API',
     
'callback' => 'my_module_display_youtube_results',
     
'type' => MENU_CALLBACK,
     
'access' => user_access('access content'),
    );
  }
  return
$items;
}
function
my_module_display_youtube_results($op = 'search', $search_term = 'default') {
 
//Log a user into youtube...
  // For testing purposes.
  // TODO: replace with your youtube user info; only needed for video upload
 
youtube_api_login('user', 'password');
  switch (
$op) {
    case
'upload':
      if (!
user_access('my_module_upload_video')) {
       
drupal_access_denied();
      }
     
//create XML array structure to be parsed into XML for video uploads/edit's
     
$xml = array();
     
$xml['entry'] = array('#name' => 'entry',
                           
'#attributes' => array('xmlns' => youtube_api_get_schema_definition('atom'),
                                                 
'xmlns:media' => youtube_api_get_schema_definition('media'),
                                                 
'xmlns:yt' => youtube_api_get_schema_definition('yt'),
                                                              ),
                            );
     
$xml['entry']['media:group'] = array('#name' => 'media:group');
     
$xml['entry']['media:group']['media:title'] = array('#name' => 'media:title',
                                                         
'#attributes' => array('type' => 'plain'),
                                                         
'#value' => 'A Test YouTube API Video');
     
$xml['entry']['media:group']['media:description'] = array('#name' => 'media:description',
                                                         
'#attributes' => array('type' => 'plain'),
                                                         
'#value' => 'A Test Upload of YouTube API functionality');
     
$xml['entry']['media:group']['media:category'] = array('#name' => 'media:category',
                                                         
'#attributes' => array('scheme' => 'http://gdata.youtube.com/schemas/2007/categories.cat'),
                                                         
'#value' => 'Entertainment');
     
$xml['entry']['media:group']['media:keywords'] = array('#name' => 'media:keywords',
                                                         
'#value' => 'test,development');
     
//Render the array structure into XML
     
$xml_string = youtube_api_create_xml('xml_tester', $xml);
     
//upload a video to youtube (must be logged in...)
      // TODO: replace with a video file from your server
     
$filepath = '/home/www/files/videos/video.mov';
     
$filename = 'video.mov';
     
$result = youtube_api_video_upload($xml_string, $filepath, $filename);
     
drupal_set_message(t('The video upload @resulted.', array('@resulted' => $result ? 'succeeded' : 'failed')));
      break;
    case
'user':
     
//Get a list of videos in the user feed of either arg(3) or the currently logged in user...
     
$videos = youtube_api_get_user_uploads($search_term);
      break;
    case
'video':
     
$video = youtube_api_get_video($video_id);
      break;
    case
'search':
    default:
     
//Perform a search of content on youtube, starting at the first record and bringing back 25 results
     
$videos = youtube_api_video_search($search_term, 1, 25);
      break;
  }
 
//Loop through videos and output them.
 
foreach ($videos as $video) {
   
$out[] = theme('youtube_api_embed', $video, $video->media['content'][0]);
  }
  return
theme('item_list', $out);
}
?>

This module was developed by Aten Design Group.

Project Information

Downloads