YouTube Developer APIs
YouTubeとは
特徴
- 容量100MB、10分までの動画ファイルを容易にアップロードし、公開できる。
- 動画を5段階で評価したり、動画やメンバーにコメントを付けられる。
- 動画をまとめたプレイリストを作成・公開する機能、お気に入り機能がある。
- 特定のメンバー同士で動画を共有できる。
YouTube Developer APIsとは
利用
API呼び出しのインタフェース
用語
→http://ja.wikipedia.org/wiki/REST
XML(eXtensible Markup Language)
→http://ja.wikipedia.org/wiki/XML
RPC(Remote Procedure Call)
→http://ja.wikipedia.org/wiki/RPC
RESTでの例。
RESTのリクエストを送信するURLは次の通り
http://www.youtube.com/api2_rest
書式
http://www.youtube.com/api2_rest?api_parameter1=value1&api_parameter2=value2&api_parameterN=valueN
APIで定義されている関数群。
- youtube.users.get_profile
- youtube.users.list_favorite_videos
- youtube.users.list_friends
動画
- youtube.videos.get_details
- youtube.videos.list_by_tag (now with paging)
- youtube.videos.list_by_user
- youtube.videos.list_featured
各APIの詳細
youtube.users.get_profile
指定したユーザーのプロフィールを取得する。
パラメータ
method: youtube.users.get_profile (REST使用時のみ指定)
dev_id: Developer ID.
user: YouTubeのユーザーを指定
例
http://www.youtube.com/api2_rest?method=youtube.users.get_profile&dev_id=99999999999&user=tk1102
結果
<?xml version="1.0" encoding="utf-8" ?> <ut_response status="ok"> <user_profile> <first_name>634</first_name> <last_name>634</last_name> <about_me>samurai</about_me> <age>26</age> <video_upload_count>0</video_upload_count> <video_watch_count>1052</video_watch_count> <homepage>http://634.ayumu-baby.com/</homepage> <hometown>yokohama</hometown> <gender>m</gender> <occupations>ninja</occupations> <companies>harakiri</companies> <city>yokohama</city> <country>JP</country> <books>makimono</books> <hobbies>chonmage</hobbies> <movies>adauchi</movies> <relationship>Taken</relationship> <friend_count>0</friend_count> <favorite_video_count>32</favorite_video_count> <currently_on>true</currently_on> </user_profile> </ut_response>
youtube.users.list_favorite_videos
指定したユーザーのお気に入り動画情報を取得する。
パラメータ
method: youtube.users.list_favorite_videos (REST使用時のみ指定)
dev_id: Developer ID.
user: YouTubeのユーザーを指定
例:
http://www.youtube.com/api2_rest?method=youtube.users.list_favorite_videos&dev_id=99999999999&user=tk1102
結果
<?xml version="1.0" encoding="utf-8" ?> <ut_response status="ok"> <video_list> <video> <author>niko810</author> <id>wVqc-978gFs</id> <title>tokyo jihen - kokode kisu shite</title> <length_seconds>284</length_seconds> <rating_avg>4.93</rating_avg> <rating_count>73</rating_count> <description>Dynamite out</description> <view_count>28579</view_count> <upload_time>1137923313</upload_time> <comment_count>3</comment_count> <tags>TOKYO JIHEN</tags> <url>http://www.youtube.com/?v=wVqc-978gFs</url> <thumbnail_url>http://sjl-static13.sjl.youtube.com/vi/wVqc-978gFs/2.jpg</thumbnail_url> </video> <video> ... </video> </video_list> </ut_response>
youtube.users.list_friends
指定したユーザーがFriends登録しているユーザー情報を取得する。
method: youtube.users.list_friends (REST使用時のみ指定)
dev_id: Developer ID.
user: YouTubeのユーザーを指定
例:
http://www.youtube.com/api2_rest?method=youtube.users.list_friends&dev_id=99999999999&user=tk1102
結果
<?xml version="1.0" encoding="utf-8" ?> <ut_response status="ok"> <friend_list /> </ut_response>
youtube.videos.get_details
指定した動画の詳細情報を取得する。
method: youtube.videos.get_details (REST使用時のみ指定)
dev_id: Developer ID.
video_id: 動画のID
例:
http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=99999999999&video_id=rdwz7QiG0lk
結果
<?xml version="1.0" encoding="utf-8" ?> <ut_response status="ok"> <video_details> <author>YouTube</author> <title>YouTube on the tube!</title> <rating_avg>4.38</rating_avg> <rating_count>254</rating_count> <tags>youtube television callforhelp ambermacarthur</tags> <description>YouTube was featured on "Call for Help with Leo Laporte" by host Amber MacArthur.</description> <update_time>1155949215</update_time> <view_count>37448</view_count> <upload_time>1130531865</upload_time> <length_seconds>423</length_seconds> <recording_date /> <recording_location /> <recording_country /> <comment_list> <comment> <author>atl4lyfe06</author> <text>what johntpuckett said was friggin priceless</text> <time>1155629605</time> </comment> <comment> <author>bananarama9</author> <text>lmao at the start? i think i heard it</text> <time>1155673304</time> </comment> </comment_list> <channel_list> <channel>Science & Technology</channel> </channel_list> <thumbnail_url>http://sjl-static12.sjl.youtube.com/vi/rdwz7QiG0lk/2.jpg</thumbnail_url> </video_details> </ut_response>
youtube.videos.list_by_tag
指定したタグに一致する動画のリストを取得する。
method: youtube.videos.list_by_tag (REST使用時のみ指定)
dev_id: Developer ID.
tag: タグ
(オプション) page: 検索結果から、取得するページ番号
(オプション) per_page: 1ページ内の情報件数
例:
http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=99999999999&tag=japan
結果
<?xml version="1.0" encoding="utf-8" ?> <ut_response status="ok"> <video_list> <video> <author /> <id>1p-PJDJV2sU</id> <title>JAPAN2006</title> <length_seconds>437</length_seconds> <rating_avg>5.00</rating_avg> <rating_count>1</rating_count> <description>"JAPAN@南港三角公園"2006/09/02開催!踊りたい放題! START AM10:00〜ALLNIGHT!前売1,000YEN 当日1,500YEN はしゃぎたい放題!</description> <view_count>982</view_count> <upload_time>1156578912</upload_time> <comment_count>0</comment_count> <tags>JAPAN MUSIC SKATE CRAZY ROCK FES OSAKA DANCE</tags> <url>http://www.youtube.com/?v=1p-PJDJV2sU</url> <thumbnail_url>http://sjl-static4.sjl.youtube.com/vi/1p-PJDJV2sU/2.jpg</thumbnail_url> </video> <video> ... </video> </video_list> </ut_response>
youtube.videos.list_by_user
指定したユーザーがアップロードした動画のリストを取得する。
method: youtube.users.list_friends (REST使用時のみ指定)
dev_id: Developer ID.
user: YouTubeのユーザーを指定
例:
http://www.youtube.com/api2_rest?method=youtube.videos.list_by_user&dev_id=99999999999&user=YouTube
結果
<?xml version="1.0" encoding="utf-8" ?> <ut_response status="ok"> <video_list> <video> <author>YouTube</author> <id>v9Qiwzgkxhw</id> <title>Hammer Time!</title> <length_seconds>123</length_seconds> <rating_avg>3.68</rating_avg> <rating_count>84</rating_count> <description>Things are really picking up around here. Not only are we adding servers and bandwidth as fast as we can, we're also pleased to report that last month's kitchen sink upgrade was successfully integrated into the snack area and we hope to have that dirty dishes bug patched shortly. As if we didn't have enough reasons to be excited, the other night we got a visit from MC HAMMER! Hammer came by the office to lend a hand and showed us the sweet new video for his song Look. While Hammer was here he dropped some serious science about the recording industry and taught us the difference between Hyphy, Thizz and Krumping. Check out the video, it's totally hyphy (see??). We gave him the grand tour and of course shot some video. Be sure to check out our awesome giant-curtain-wall-substitutes and the crazy tribal pattern we pimped our office walls with (it actually represents bandwidth but we all got it tattooed on our ankles anyway).</description> <view_count>51910</view_count> <upload_time>1139539877</upload_time> <comment_count>83</comment_count> <tags>YouTube MC Hammer</tags> <url>http://www.youtube.com/?v=v9Qiwzgkxhw</url> <thumbnail_url>http://sjl-static15.sjl.youtube.com/vi/v9Qiwzgkxhw/2.jpg</thumbnail_url> </video> <video> ... </video> </video_list> </ut_response>
youtube.videos.list_featured
YouTubeに最近追加された動画を25タイトル取得する。
method: youtube.videos.list_featured (REST使用時のみ指定)
dev_id: Developer ID.
例:
http://www.youtube.com/api2_rest?method=youtube.videos.list_featured&dev_id=99999999999
結果
<?xml version="1.0" encoding="utf-8" ?> <ut_response status="ok"> <video_list> <video> <author>NBC</author> <id>MBwEd_g62Hk</id> <title>Heroes -- In Theater trailer</title> <length_seconds>158</length_seconds> <rating_avg>3.67</rating_avg> <rating_count>1288</rating_count> <description>NBC's new show "Heroes" is about ordinary people who find something extraordinary in themselves. We all have a path in discovering our purpose, but how will these characters use their powers to discover theirs? Check out the premiere of "Heroes" on Monday, September 25th @ 9/8c only on NBC.</description> <view_count>163688</view_count> <upload_time>1156454211</upload_time> <comment_count>414</comment_count> <tags>Heroes powers abilities super human extraordinary Greg Grunberg Ali Larter Hayden Panettiere</tags> <url>http://www.youtube.com/?v=MBwEd_g62Hk</url> <thumbnail_url>http://sjl-static8.sjl.youtube.com/vi/MBwEd_g62Hk/2.jpg</thumbnail_url> </video> <video> ... </video> </video_list> </ut_response>
エラーとエラーコード
<ut_response status="fail">
<error>
<code>7</code>
<description>Missing dev_id parameter.</description>
</error>
</ut_response>
エラーコードは以下の通り
1 : YouTube Internal Error
YouTube APIの内部に問題が発生している。
2 : Bad XML-RPC format parameter
XML-RPC API呼び出しの際に不正なパラメータを送信している。
3 : Unknown parameter specified
不正なパラメータを送信。
4 : Missing required parameter
必要なパラメータが送信されていない。
5 : No method specified
メソッドが送信されていない。
6 : Unknown method specified
定義されていないメソッドが送信された。
7 : Missing dev_id parameter
dev_idのパラメータがみつからない。
8 : Bad or unknown dev_id specified
developer profileで登録されていない。
その他、個別のエラーコードも存在する。
リンク
Youtube
DataAPI
リファレンス
http://code.google.com/intl/ja/apis/youtube/reference.html
動画の検索
ベースURL
http://gdata.youtube.com/feeds/api/videos?
パラメータ
-alt
–Feedのフォーマット指定。atom、rss、json。
-author
–アップロードユーザー
-max-results
–最大件数
-start-index
–検索結果の先頭インデックス番号
-vq
–検索ワード。URLエスケープが必要。完全一致検索の場合は引用符(エスケープ処理をおこなう。つまり%22)で囲む。NOT(-)とOR(|)も利用可能(同じくエスケープする)。
-orderby
-format
-lr
-racy
-restriction
-time

