Example -- Basic examples of Services_YouTube
Basic examples of Services_YouTube
The following examples show how to use some basic features
of Services_YouTube:
Пример 62-1. Retrieves the public parts of a user profile. require_once 'Services/YouTube.php';
$dev_id = "YOUR_DEV_ID";
$user_id = "USER_ID";
$youtube = new Services_YouTube($dev_id, array('usesCache' => true));
$user = $youtube->getProfile($user_id);
$profile = $user->user_profile;
print "{$profile->first_name} {$profile->last_name} :({$profile->video_watch_count} Watched.)\n"; |
|
Пример 62-2. Lists a user's favorite videos. require_once 'Services/YouTube.php';
$dev_id = "YOUR_DEV_ID";
$user_id = "USER_ID";
$youtube = new Services_YouTube($dev_id, array('usesCache' => 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";
} |
|
Пример 62-3. Lists a user's friends. require_once 'Services/YouTube.php';
$dev_id = "YOUR_DEV_ID";
$user_id = "USER_ID";
$youtube = new Services_YouTube($dev_id, array('usesCache' => true));
$users = $youtube->listFriends($user_id);
foreach ($users->xpath('//friend') as $i => $friend) {
print "{$friend->user} : Upload: {$friend->video_upload_count}";
} |
|
Пример 62-4. Lists all videos that have the specified tag. require_once 'Services/YouTube.php';
$dev_id = "YOUR_DEV_ID";
$tag = "test";
$youtube = new Services_YouTube($dev_id, array('usesCache' => 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";
} |
|
Пример 62-5. Lists all videos that were uploaded by the specified user. require_once 'Services/YouTube.php';
$dev_id = "YOUR_DEV_ID";
$user_id = "USER_ID";
$youtube = new Services_YouTube($dev_id, array('usesCache' => 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";
} |
|
Пример 62-7. Displays the details for a video. require_once 'Services/YouTube.php';
$dev_id = "YOUR_DEV_ID";
$video_id = "VIDEO_ID";
$youtube = new Services_YouTube($dev_id, array('usesCache' => 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 />";
} |
|
HIVE: All information for read only. Please respect copyright! |
|