Eric R. Meyers > WWW-YouTube-2008.0728 > WWW::YouTube::XML::API

Download:
WWW-YouTube-2008.0728.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 2008.0728   Source  

NAME ^

WWW::YouTube::XML::API - How to Interface with YouTube using HTTP Protocol and GData XML Atom API.

http://code.google.com/apis/youtube/developers_guide_protocol.html

SYNOPSIS ^

use WWW::YouTube;

## Standard feeds

foreach my $feed qw( top_rated top_favorites most_viewed most_recent most_discussed most_linked most_responded recently_featured watch_on_mobile ) { print "##\n## /feeds/api/standardfeeds/$feed\n##\n";

   $request = WWW::YouTube::XML::API::standardfeeds( $feed );

   $result = WWW::YouTube::XML::API::ua_request( $request );

   if ( $result->is_success() )
   {
      $xml_tree = WWW::YouTube::XML::parse_result( $result );

      WWW::YouTube::XML::example_show_xml_links( $xml_tree );

      $xml_tree->delete();

   }
   else
   {
      print $result->as_string() . "\nFAILURE\n";

   } ## end if

} ## end foreach

## Uploaded by user

my $request = WWW::YouTube::XML::API::uploaded_by_userid( $userid );

my $result = WWW::YouTube::XML::API::ua_request( $request );

if ( $result->is_success() ) { my $xml_tree = XML::TreeBuilder->new();

   $xml_tree->parse( $result->content() );

   $xml_tree->eof();

   # do something here, then

   $xml_tree->delete();

} ## end if

OPTIONS ^

--xml_ua_dmp

user agent transaction dump

--xml_request_dmp

transaction request dump

--xml_result_dmp

transaction result dump

DESCRIPTION ^

XML::API stands for XML Application Programming Interface

See: http://code.youtube.com http://code.google.com/apis/youtube http://code.google.com/apis/youtube/developers_guide_protocol.html

Demo

WWW::YouTube::XML::demo()

Retrieving and searching for videos

1. Standard video feeds

foreach my $feed qw( top_rated top_favorites most_viewed most_recent most_discussed most_linked most_responded recently_featured watch_on_mobile ) { print "##\n## /feeds/api/standardfeeds/$feed\n##\n";

   $request = WWW::YouTube::XML::API::standardfeeds( $feed );

   $result = WWW::YouTube::XML::API::ua_request( $request );

   if ( $result->is_success() )
   {
      $xml_tree = WWW::YouTube::XML::parse_result( $result );

      WWW::YouTube::XML::example_show_xml_links( $xml_tree );

      $xml_tree->delete();

   }
   else
   {
      print $result->as_string() . "\nFAILURE\n";

   } ## end if

} ## end foreach

NOTE: This also works. WWW::YouTube::XML::API::standardfeeds( 'US/top_rated?time=today' );

2. Videos uploaded by a specific user

$request = WWW::YouTube::XML::API::uploaded_by_userid([ $userid ]);

$result = WWW::YouTube::XML::API::ua_request( $request );

3. Related videos

Follow a link with rel="http://gdata.youtube.com/schemas/2007#video.related".

4. Browsing with categories and keywords

$request = WWW::YouTube::XML::API::browse( $categories_or_keywords );

$result = WWW::YouTube::XML::API::ua_request( $request );

See: http://code.google.com/apis/youtube/developers_guide_protocol.html#Browsing_with_Categories_and_Keywords

5. Searching for videos

$request = WWW::YouTube::XML::API::search( 'vq' => 'funny+video', 'max-results' => 10 );

$result = WWW::YouTube::XML::API::ua_request( $request );

See: http://code.google.com/apis/youtube/developers_guide_protocol.html#Searching_for_Videos

Uploading videos

$request = WWW::YouTube::XML::API::upload_by_userid_filename( $userid, $filename, $xml_tree );

## ADD FILE PART ## See WWW::YouTube::XML::example_upload

$result = WWW::YouTube::XML::API::ua_request( $request );

Updating and deleting videos

1. Updating a video entry

$request = WWW::YouTube::XML::API::get_uploaded_by_userid_videoid( $userid, $videoid );

$result = WWW::YouTube::XML::API::ua_request( $request );

$xml_tree = WWW::YouTube::XML::parse_result( $result );

## Edit the Entry, then put the update

$request = WWW::YouTube::XML::API::put_uploaded_by_userid_videoid( $userid, $videoid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Deleting a video

$request = WWW::YouTube::XML::API::remove_uploaded_by_userid_videoid( $userid, $videoid );

$result = WWW::YouTube::XML::API::ua_request( $request );

Using community features

1. Adding a rating

$request = WWW::YouTube::XML::API::rating_by_videoid( $videoid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Comments

1. Retrieving comments for a video

$request = WWW::YouTube::XML::API::comments_by_videoid( $videoid );

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Adding a comment in response to a video

$request = WWW::YouTube::XML::API::comment_by_videoid( $videoid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

3. Video responses

1. Retrieving a list of video responses

$request = WWW::YouTube::XML::API::responses_by_videoid( $videoid );

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Adding a video response

$request = WWW::YouTube::XML::API::response_by_videoid( $videoid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

3. Deleting a video response

$request = WWW::YouTube::XML::API::remove_response_by_videoid_responseid( $videoid, $responseid );

$result = WWW::YouTube::XML::API::ua_request( $request );

4. Adding a complaint

$request = WWW::YouTube::XML::API::complaint_by_videoid( $videoid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

5. Sharing videos with other users

$request = WWW::YouTube::XML::API::contact_by_userid( $userid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

Saving and collecting videos

1. Favorite videos

1. Retrieving a user's favorite videos

$request = WWW::YouTube::XML::API::favorites_by_userid([ $userid ]);

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Adding a favorite video

$request = WWW::YouTube::XML::API::favorite_by_userid( $userid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

3. Deleting a favorite video

$request = WWW::YouTube::XML::API::remove_favorite_by_userid_videoid( $userid, $videoid );

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Playlists

1. Retrieving a user's playlists

$request = WWW::YouTube::XML::API::playlists_by_userid([ $userid ]);

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Retrieving a single playlist

Follow a gd:feedLink with rel="http://gdata.youtube.com/schemas/2007#playlist".

3. Adding a playlist

$request = WWW::YouTube::XML::API::playlist_by_userid( $userid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

4. Updating a playlist

$request = WWW::YouTube::XML::API::get_playlist_by_userid_playlistid( $userid, $playlistid );

$result = WWW::YouTube::XML::API::ua_request( $request );

$xml_tree = WWW::YouTube::XML::parse_result( $result );

## Edit the Entry, then put the update

$request = WWW::YouTube::XML::API::put_playlist_by_userid_playlistid( $userid, $playlistid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

1. Adding a video to a playlist

$request = WWW::YouTube::XML::API::add_to_playlist_by_playlistid( $playlistid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Editing video information in a playlist

$request = WWW::YouTube::XML::API::get_entry_by_playlistid_entryid( $playlistid, $entryid );

$result = WWW::YouTube::XML::API::ua_request( $request );

$xml_tree = WWW::YouTube::XML::parse_result( $result );

## Edit the Entry, then put the update

$request = WWW::YouTube::XML::API::put_entry_by_playlistid_entryid( $playlistid, $entryid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

3. Removing a video from a playlist

$request = WWW::YouTube::XML::API::remove_entry_by_playlistid_entryid( $playlistid, $entryid );

$result = WWW::YouTube::XML::API::ua_request( $request );

5. Deleting a playlist

$request = WWW::YouTube::XML::API::remove_playlist_by_userid_playlistid( $userid, $playlistid );

$result = WWW::YouTube::XML::API::ua_request( $request );

3. Subscriptions

1. Retrieving a user's subscriptions

$request = WWW::YouTube::XML::API::subscriptions_by_userid([ $userid ]);

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Adding a subscription

$request = WWW::YouTube::XML::API::subscribe_by_userid( $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

3. Deleting a subscription

$request = WWW::YouTube::XML::API::remove_subscription_by_userid_subscriptionid( $userid, $subscriptionid );

$result = WWW::YouTube::XML::API::ua_request( $request );

Enabling user interaction

1. User profiles

1. Retrieving a user's profile

$request = WWW::YouTube::XML::API::profile_by_userid([ $userid ]);

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Contacts

1. Retrieving a user's contacts

$request = WWW::YouTube::XML::API::contacts_by_userid([ $userid ]);

$result = WWW::YouTube::XML::API::ua_request( $request );

2. Adding a contact

$request = WWW::YouTube::XML::API::add_contact_by_userid( $userid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

3. Updating a contact

$request = WWW::YouTube::XML::API::get_contact_by_userid_contactid( $userid, $contactid );

$result = WWW::YouTube::XML::API::ua_request( $request );

$xml_tree = WWW::YouTube::XML::parse_result( $result );

# Edit the Entry, then put the update

$request = WWW::YouTube::XML::API::put_contact_by_userid_contactid( $userid, $contactid, $xml_tree );

$result = WWW::YouTube::XML::API::ua_request( $request );

4. Deleting a contact

$request = WWW::YouTube::XML::API::remove_contact_by_userid_contactid( $userid, $contactid );

$result = WWW::YouTube::XML::API::ua_request( $request );

SEE ALSO ^

WWW::YouTube WWW::YouTube::ML::API WWW::YouTube::HTML::API WWW::YouTube::XML

AUTHOR ^

 Copyright (C) 2008 Eric R. Meyers E<lt>Eric.R.Meyers@gmail.comE<gt>
syntax highlighting: