C# Youtube 影片資訊 JSON (回傳影片瀏覽次數)
/// <summary>
/// 取得 Youtube 影片觀看次數
/// </summary>
/// <param name="youtubecode">Youtube 影片碼</param>
/// <returns></returns>
public
static
string
GetYoutubeViewcount(
string
youtubecode)
{
System.Net.HttpWebRequest request = WebRequest.Create(url)
as
HttpWebRequest;
try
{
using
(HttpWebResponse response = request.GetResponse()
as
HttpWebResponse)
{
StreamReader reader =
new
StreamReader(response.GetResponseStream());
string
retVal = reader.ReadToEnd();
JObject googleSearch = JObject.Parse(retVal);
return
googleSearch[
"entry"
][
"yt$statistics"
][
"viewCount"
].ToString();
}
}
catch
{
return
"0"
;
}
}
參考網站:http://patw.idv.tw/blog/archives/521/asp-net-c-access-to-youtube-videos-watched/
標籤: C#
0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁