【问题标题】:How can i get the number of views in the Google Youtube API?如何获取 Google Youtube API 中的观看次数?
【发布时间】:2013-09-01 08:23:44
【问题描述】:

我正在使用 YouTube API 非常简单地获取一些视频并在我的 iPhone 应用程序的 UITableView 中显示它们,

问题是这样的:

1.视频的观看次数总是返回null

2.我没有得到上传的视频名称。

这是我的代码

    NSString *title = [[entry title] stringValue];
    NSString *viewCount=[[[(GDataEntryYouTubeVideo *)entry statistics]viewCount] stringValue];
    NSLog(@"%@",viewCount); // returns null
    NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];

谢谢。

【问题讨论】:

  • 您的“title”变量中是否返回了字符串?
  • 标题中没有,我得到了完美的结果,我也得到了缩略图。但我无法获得观看次数

标签: iphone ios youtube-api


【解决方案1】:

我怀疑你没有有效的“entry”对象,证明这一点的方法是这样做:

if(entry)
{
    GDataYouTubeStatistics * statistics = [entry statistics];
    if(statistics)
    {
        NSNumber * viewNumber = [statistics videoWatchCount];
        NSLog( @"number of views is %ld", [viewNumber integerValue]);

    } else {
        NSLog( @"entry appears to be valid, but there are no stats with it");
    }
} else {
    NSLog( @"what do you know, entry is nil");
}

另外,查看API on code.google.com,您可能想尝试“videoWatchCount”而不是“viewCount”。

【讨论】:

  • GDataYouTubeStatistics * statistics = [条目统计];大多数情况下它返回null,如果是那么我得到的视图数是0
  • 您认为我必须向 GDataQueryYouTube 添加一些内容吗?然后他们将获取 videoWatchCount
  • 如果 "statistics" 为 nil,您将不会在 "videoWatchCount" 或 "viewCount" 中得到任何有效的信息。
  • 但在 youtube 中,这有一些观看次数,但在我的应用程序中我没有得到,所以会有一些问题
【解决方案2】:

您是否在请求中传递了 统计 部分?

part 参数指定 API 响应将包含的一个或多个视频资源属性的逗号分隔列表。您可以在参数值中包含的部分名称是 id、sn-p、contentDetails、fileDetails、player、processingDetails、recordingDetails、statistics、status、suggestions 和 topicDetails。如果参数标识包含子属性的属性,则子属性将包含在响应中。例如,在视频资源中,sn-p 属性包含 channelId、title、description、tags 和 categoryId 属性。因此,如果您设置 part=sn-p,API 响应将包含所有这些属性。 (字符串)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-17
    • 2011-03-20
    • 2014-11-23
    • 2015-08-30
    • 2019-03-12
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多