1

美好的一天,我是这个 Youtube GData api 的新手,我无法访问特定播放列表的视频列表。

我首先做的是获取特定用户的播放列表列表。它返回了这样的东西GDataEntryYouTubePlaylistLink 0x888ea20: {v:2.1 title:Playlist Title summary: contentSrc:https://gdata.youtube.com/feeds/api/playlists/PL5......92D127 etag:W/"D04N.....WhJVEU8." authors:1 categories:1 links:related,alternate,self id:tag:youtube.com,2008:user:MyYoutubeUser:playlist:PL5......92D127 countHint:7 unparsed:<media:group>}

我了解到 countHint 是该播放列表中的视频数量。现在,我想得到那些视频。

我尝试创建一个可以这样做的函数,但我不知道我将使用什么 FeedID:

    GDataServiceGoogleYouTube *service = [self youTubeService];

NSString *feedID = kGDataYouTubeUserFeedIDPlaylists; //this was the feedID i used to get the list of playlist of a user
NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"MyYoutubeUser"
                                                        userFeedID:feedID];

[service fetchFeedWithURL:feedURL
                 delegate:self
        didFinishSelector:@selector(request:finishedLoading:error:)];
4

1 回答 1

1

我能够找到我的问题的解决方案。我希望它也可以帮助你。

在我的 viewDidLoad 中,我调用了 loadYoutube 和 loadYoutubePlaylist 函数。

  • loadYoutube -> 为我们提供给定用户的 URL 和 feedID。在我的例子中,feedID 是 kGDataYouTubeUserFeedIDUploads 因为我只想获取用户上传的播放列表和视频。
  • loadYoutubePlaylist -> 为我们提供用户播放列表的 URL。feedID 是 kGDataYouTubeUserFeedIDPlaylists
  • loadYoutubeVideosPerPlaylist -> 为我们提供每个播放列表的视频 URL。

这是代码的样子:

- (void)loadYoutube
{
    GDataServiceGoogleYouTube *service = [self youTubeService];

    NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
    NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"USERNAME"
                                                         userFeedID:uploadsID];
    NSLog(@"loadYoutube URL: %@", feedURL);
    [service fetchFeedWithURL:feedURL
                     delegate:self
            didFinishSelector:@selector(request:finishedLoadingYoutubeWithFeed:error:)];
}

- (void)loadYoutubePlaylist
{
    GDataServiceGoogleYouTube *service = [self youTubeService];

    NSString *feedID = kGDataYouTubeUserFeedIDPlaylists;
    NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"USERNAME"
                                                            userFeedID:feedID];
    NSLog(@"loadYoutubePlaylist URL: %@", feedURL);
    [service fetchFeedWithURL:feedURL
                     delegate:self
            didFinishSelector:@selector(request:finishedLoadingPlaylistWithFeed:error:)];
}

- (void)loadYoutubeVideosPerPlaylist:(NSString *)urlString
{
    GDataServiceGoogleYouTube *service = [self youTubeService];
    NSURL *feedURL = [NSURL URLWithString:urlString];

    NSLog(@"loadYoutubeVideosPerPlaylist URL: %@", feedURL);

    [service fetchFeedWithURL:feedURL
                     delegate:self
            didFinishSelector:@selector(request:finishedLoadingYoutubeVideosPerPlaylistWithFeed:error:)];
}

这是 Youtube 请求..

#pragma mark - Youtube Requests

- (void)request:(GDataServiceTicket *)ticket finishedLoadingYoutubeWithFeed:(GDataFeedBase *)aFeed error:(NSError *)error
{

}

- (void)request:(GDataServiceTicket *)ticket finishedLoadingPlaylistWithFeed:(GDataFeedBase *)aFeed error:(NSError *)error
{
    if (kGDataYouTubeUserFeedIDPlaylists) {
        self.playlistFeed = (GDataFeedYouTubeVideo *)aFeed;

        NSArray *feedArray = [self.playlistFeed entries];
        for (int i = 0; i < [feedArray count]; i++) {
            GDataEntryBase *entry = [[self.playlistFeed entries] objectAtIndex:i];
            NSString *title = [[entry title] stringValue];
            [playlist addObject:NSLocalizedString(title, @"playlistTitle")];
            NSLog(@"%@", [[entry content] sourceURI]);
            [videoPlaylistURLArray addObject:[[entry content] sourceURI]];
        }
    }
    if (!error) {
        [self addMenuButtons];
        [self setPlaylistIndex:0];
        [SVProgressHUD showSuccessWithStatus:@"Success!"];
    }else{
        [SVProgressHUD showErrorWithStatus:@"Failed Fetching Playlist."];
    }
}

- (void)request:(GDataServiceTicket *)ticket finishedLoadingYoutubeVideosPerPlaylistWithFeed:(GDataFeedBase *)aFeed error:(NSError *)error
{
    self.feed = (GDataFeedYouTubeVideo *)aFeed;
    [self.youtubeTable reloadData];
}
于 2012-12-19T02:20:28.753 回答