【问题标题】:How to load more than 50 youtube videos on UITableView?如何在 UITableView 上加载 50 多个 youtube 视频?
【发布时间】:2023-03-14 13:31:01
【问题描述】:

我正在使用 AFNetworking 来解析 UITableView 上的 JSON 数据。 YouTube api 为最多 50 个视频提供 JSON 数据。我需要加载超过 100 个视频,但我不知道该怎么做。

这是我用来从 API 获取文件的网址:

http://gdata.youtube.com/feeds/api/playlists/PL7CF5B0AC3B1EB1D5?v=2&alt=jsonc&max-results=50

这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];


    NSString *urlAsString = @"http://gdata.youtube.com/feeds/api/playlists/PL7CF5B0AC3B1EB1D5?v=2&alt=jsonc&max-results=50";


    NSURL *url = [NSURL URLWithString:urlAsString];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    // This will initiate the request and parse the data using apples JSONSerialization

    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {



        self.videoMetaData = [JSON valueForKeyPath:@"data.items.video"];

        // This will have all the sq and hq thumbnails

        self.allThumbnails = [JSON valueForKeyPath:@"data.items.video.thumbnail"];

【问题讨论】:

    标签: iphone objective-c json uitableview youtube-api


    【解决方案1】:

    提供start-index-选项。例如:

    1. 使用此 URL 获得 50 个结果:
      http://gdata.youtube.com/feeds/api/playlists/PL7CF5B0AC3B1EB1D5?v=2&alt=jsonc&max-results=50
    2. 通过添加 &start-index=51:
      http://gdata.youtube.com/feeds/api/playlists/PL7CF5B0AC3B1EB1D5?v=2&alt=jsonc&max-results=50&start-index=51 获取接下来的 50 个结果

    请参阅YouTube API v. 2.0 reference

    【讨论】:

    • 好的,所以我必须使用多个 url。如何在一页上查看所有结果?
    • 例如,您可以将结果放在NSMutableArray 中。
    • 那么我应该多次使用 AFJSONRequestOperation 然后将结果添加到新数组中吗?
    • 具体如何操作由您决定,但是是的,这是一个解决方案。
    猜你喜欢
    • 2017-08-23
    • 2018-04-06
    • 2015-06-24
    • 2018-06-11
    • 1970-01-01
    • 2017-08-05
    • 2023-03-08
    • 2012-11-08
    • 1970-01-01
    相关资源
    最近更新 更多