やりたいこと
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<video>(videoEntryUrl);
- printVideoEntry(video);
- Console.ReadKey();
- }
- static void printVideoEntry(Video video)
- {
- Console.WriteLine("Title: " + video.Title);
- Console.WriteLine(video.Description);
- Console.WriteLine("Keywords: " + video.Keywords);
- Console.WriteLine("Uploaded by: " + video.Uploader);
- if (video.YouTubeEntry.Location != null)
- {
- Console.WriteLine("Latitude: " + video.YouTubeEntry.Location.Latitude);
- Console.WriteLine("Longitude: " + video.YouTubeEntry.Location.Longitude);
- }
- if (video.Media != null && video.Media.Rating != null)
- {
- Console.WriteLine("Restricted in: " + video.Media.Rating.Country);
- }
- if (video.IsDraft)
- {
- Console.WriteLine("Video is not live.");
- string stateName = video.Status.Name;
- if (stateName == "processing")
- {
- Console.WriteLine("Video is still being processed.");
- }
- else if (stateName == "rejected")
- {
- Console.Write("Video has been rejected because: ");
- Console.WriteLine(video.Status.Value);
- Console.Write("For help visit: ");
- Console.WriteLine(video.Status.Help);
- }
- else if (stateName == "failed")
- {
- Console.Write("Video failed uploading because:");
- Console.WriteLine(video.Status.Value);
- Console.Write("For help visit: ");
- Console.WriteLine(video.Status.Help);
- }
- if (video.ReadOnly == false)
- {
- Console.WriteLine("Video is editable by the current user.");
- }
- if (video.RatingAverage != -1)
- {
- Console.WriteLine("Average rating: " + video.RatingAverage);
- }
- if (video.ViewCount != -1)
- {
- Console.WriteLine("View count: " + video.ViewCount);
- }
- Console.WriteLine("Thumbnails:");
- foreach (MediaThumbnail thumbnail in video.Thumbnails)
- {
- Console.WriteLine("\tThumbnail URL: " + thumbnail.Url);
- Console.WriteLine("\tThumbnail time index: " + thumbnail.Time);
- }
- Console.WriteLine("Media:");
- foreach (Google.GData.YouTube.MediaContent mediaContent in video.Contents)
- {
- Console.WriteLine("\tMedia Location: " + mediaContent.Url);
- Console.WriteLine("\tMedia Type: " + mediaContent.Format);
- Console.WriteLine("\tDuration: " + mediaContent.Duration);
- }
- }
- }
- }
- }
- </video>
実行結果
こんなのが出力されたので、ひとまず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 件のコメント:
コメントを投稿