如何从YouTube API检索视频观看次数

时间:2013-04-29 19:10:19

标签: google-api youtube-api

我目前正在探索使用Google的YouTube API从YouTube频道检索观看次数。(Google.Apis.Youtube.v3.dll)。我可以成功检索有关频道中视频的信息,但无法检索实际的观看次数。

示例:

foreach (var channel in channelsListResponse.Items)
  {
   var viewcount = channel.Statistics.ViewCount;

我不断收到“未将对象引用设置为对象实例”错误。

有没有人有.net代码示例使用YouTube API检索视图计数或知道可能导致此类错误的原因?

2 个答案:

答案 0 :(得分:0)

这对你有帮助吗?它会检索用户个人资料https://developers.google.com/youtube/2.0/developers_guide_dotnet#Retrieving_a_User_Profile

的所有信息

答案 1 :(得分:0)

使用DotNetOpenAuth.OAuth2;

使用Google.Apis.Authentication; 使用Google.Apis.Authentication.OAuth2; 使用Google.Apis.Authentication.OAuth2.DotNetOpenAuth; 使用Google.Apis.Samples.Helper; 使用Google.Apis.Services; 使用Google.Apis.Util; 使用Google.Apis.Youtube.v3; 使用Google.Apis.Youtube.v3.Data;

var youtube = new YoutubeService(new BaseClientService.Initializer()       {         Authenticator = auth       });

var viewcount = youtube.Videos.List(“在此处输入视频ID”,“统计数据”);