Пример

Пример – Basic examples of Services_YouTube

Basic examples of Services_YouTube

The following examples show how to use some basic features of Services_YouTube:

Retrieves the public parts of a user profile.

<?php
require_once 'Services/YouTube.php';

$dev_id "YOUR_DEV_ID";
$user_id "USER_ID";
$youtube = new Services_YouTube($dev_id, array('useCache' => true));
$user $youtube->getProfile($user_id);
$profile $user->user_profile;
print 
"{$profile->first_name} {$profile->last_name} :({$profile->video_watch_count} Watched.)\n";
?>

Lists a user's favorite videos.

<?php
require_once 'Services/YouTube.php';

$dev_id "YOUR_DEV_ID";
$user_id "USER_ID";
$youtube = new Services_YouTube($dev_id, array('useCache' => true));
$videos $youtube->listFavoriteVideos($user_id);
foreach (
$videos->xpath('//video') as $i => $video) {
    print 
"<img src='{$video->thumbnail_url}' alt='{$video->title}' />\n";
    print 
"<a href='{$video->url}'>URL</a><br />\n";
}
?>

Lists a user's friends.

<?php
require_once 'Services/YouTube.php';

$dev_id "YOUR_DEV_ID";
$user_id "USER_ID";
$youtube = new Services_YouTube($dev_id, array('useCache' => true));
$users $youtube->listFriends($user_id);
foreach (
$users->xpath('//friend') as $i => $friend) {
    print 
"{$friend->user} : Upload: {$friend->video_upload_count}";
}
?>

Lists all videos that have the specified tag.

<?php
require_once 'Services/YouTube.php';

$dev_id "YOUR_DEV_ID";
$tag "test";
$youtube = new Services_YouTube($dev_id, array('useCache' => true));
$videos $youtube->listByTag($tag);
foreach (
$videos->xpath('//video') as $i => $video) {
    print 
"<img src='{$video->thumbnail_url}' alt='{$video->title}' />\n";
    print 
"<a href='{$video->url}'>URL</a><br />\n";
}
?>

Lists all videos that were uploaded by the specified user.

<?php
require_once 'Services/YouTube.php';

$dev_id "YOUR_DEV_ID";
$user_id "USER_ID";
$youtube = new Services_YouTube($dev_id, array('useCache' => true));
$videos $youtube->listByUser($user_id);
foreach (
$videos->xpath('//video') as $i => $video) {
    print 
"<img src='{$video->thumbnail_url}' alt='{$video->title}' />\n";
    print 
"<a href='{$video->url}'>URL</a><br />\n";
}
?>

Lists the most recent 25 videos that have been featured on the front page of the YouTube site.

<?php
require_once 'Services/YouTube.php';

$dev_id "YOUR_DEV_ID";
$youtube = new Services_YouTube($dev_id, array('useCache' => true));
$videos $youtube->listFeatured();
foreach (
$videos->xpath('//video') as $i => $video) {
    print 
"<img src='{$video->thumbnail_url}' alt='{$video->title}' />\n";
    print 
"<a href='{$video->url}'>URL</a><br />\n";
}
?>

Displays the details for a video.

<?php
require_once 'Services/YouTube.php';

$dev_id "YOUR_DEV_ID";
$video_id "VIDEO_ID";
$youtube = new Services_YouTube($dev_id, array('useCache' => true));
$video $youtube->getDetails($video_id);
$details $video->video_details;
print 
"{$details->title} : ({$details->tags}) : RATE: {$details->rating_avg} in {$detials->rating_count}";
print 
"<img src='{$details->thumbnail_url}' alt={$details->title}><hr /><hr />";
foreach (
$details->xpath('//comment') as $i => $comment) {
    print 
"{$comment->author} : {$comment->text}<hr />";
}
?>
    Поддержать сайт на родительском проекте КГБ