例
例 – Services_YouTube の基本的な使用法
Services_YouTube の基本的な使用法
以下の例で、
Services_YouTube の基本的な使用法を示します。
<?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";
?>
<?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";
}
?>
<?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}";
}
?>
<?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";
}
?>
指定したユーザがアップロードしたすべての画像の一覧表示
<?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";
}
?>
YouTube のトップページに掲載された、最近の 25 本の画像の一覧表示
<?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";
}
?>
<?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 />";
}
?>