2012年12月17日月曜日

c# youtube api 2 (Api呼んでみる)

やりたいこと
Developerkeyを入手して、Apiを呼び出してみるところまでやってみる。


準備
■参考にしたサイト
本家
https://developers.google.com/youtube/2.0/developers_guide_dotnet?hl=ja
デベロッパーキー入手の参考にしたサイト
http://ryushimiz.blogspot.jp/2010/02/youtube-api.html

手順1 Developerkeyの入手
上述のデベロッパーキー入手の参考にしたサイトを参考にしてdeveloperkeyを作成する。


手順2 Apiをコール
本家のページにあるサンプルをコピーして以下のようなコードを作成する。
YouTubeRequestSettingsをnewするところでは、developerkey飲みを引数とした。

※本家のサイトではclientIDなるものも引数としているが、
cleinetIDがなんなのかわからなかったことと、developerkeyの入手画面でももう必要ないみたいなことが書いてあったので無視した。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// youtube
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.YouTube;
using Google.GData.Extensions.MediaRss;
using Google.YouTube;

namespace YoutubeTest001
{
    class Program
    {
        static void Main(string[] args)
        {
            string developerKey = "作成したデベロッパーキー";
            YouTubeRequestSettings settings = new YouTubeRequestSettings("example app", developerKey);
            YouTubeRequest request = new YouTubeRequest(settings);

            Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/ADos_xW4_J0");
            Video video = request.Retrieve


実行結果
こんなのが出力されたので、ひとまずApiの呼び出しには成功しているのではと思ってる。
------------------------------------
Title: Introduction to Google Data
Jeff Fisher walks through basic history and concepts behind the Google Data prot
ocol. Visit the documentation for more information and list of available APIs:
http://code.google.com/apis/gdata/
Keywords:
Uploaded by: googledevelopers
------------------------------------
0 件のコメント:
コメントを投稿