美好的一天,我是这个 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:)];
我能够找到我的问题的解决方案。我希望它也能帮助你。
在我看来,我调用了loadYoutube和loadYoutubePlaylist函数。
- loadYoutube -> 为我们提供了给定用户的 URL 和什么 feedID。就我而言,feedID是kGDataYouTubeUserFeedIDUpload,因为我只想获取用户上传的播放列表和视频。
- loadYoutubePlaylist -> 为我们提供了用户播放列表的 URL。 feedID is 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];
}