views:

333

answers:

3

Hi,

I need to list a specific users uploaded videos (YouTube) in a UITableView. I've downloaded the GData source and example projects (not iphone specific) but I can't seem to get it to work. Does anybody know of any good (or any at all ;)) tutorials out there?

Best regards, Magnus

+3  A: 

Assuming you have included the GData client libraries to your project, you need to make a call to fetch the user's uploads, and then display them. Here's the simplest way I can think of:

Create an instance variable in your table view controller class that will hold the feed data returned from the YouTube API.

RootViewController.h

#import "GDataYouTube.h"
#import "GDataServiceGoogleYouTube.h"

@interface RootViewController : UITableViewController {
    GDataFeedYouTubeVideo *feed;
}

@property (nonatomic, retain) GDataFeedYouTubeVideo *feed;

Inside the implementation file, make a call to the API to fetch all uploaded videos. Inside the callback selector request:finishedWithFeed:error, store the results in whatever format suits, and reload the table view. In the table views cellForRowAtIndexPath method, format the cell as desired:

RootViewController.m

// get the youtube service
GDataServiceGoogleYouTube *service = [self youTubeService];

// feed id for user uploads
NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
// construct the feed url
NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"annoyingorange"
                                            userFeedID:uploadsID];

// make API call
[service fetchFeedWithURL:feedURL
         delegate:self
         didFinishSelector:@selector(request:finishedWithFeed:error:)];

Checkout the full source code for RootViewController.

Anurag
Great! That example solved exactly what I was looking for. Thanks!/M
Dumble
Glad it helped. Cheers!
Anurag
A: 

Thanks!!! it's real good!

dongbokhong
A: 

Thanks for the link Anurag, works very well!

I did some slight changes to the above code in order to fetch a feed with a search query instead of a user channel, unfortunately I always end up with a blank table view or runtime termination (although I specified the max number of results).

Here is my viewDidLoad function:

- (void)viewDidLoad {

GDataServiceGoogleYouTube *service = [self youTubeService];

NSString *searchString = @"football";

NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;

NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForFeedID:nil];

GDataQueryYouTube* query = [GDataQueryYouTube  youTubeQueryWithFeedURL:feedURL];

[query setVideoQuery:searchString];

[query setMaxResults:5];

[service fetchFeedWithQuery:query delegate:self didFinishSelector:@selector(entryListFetchTicket:finishedWithFeed:)];

[super viewDidLoad];

}

I passed by this page http://everburning.com/news/mytube-searching-for-fun-and-profit/ and other query fetch examples (objc but not for the iphone) but can't seem to get it work.

Any help would be appreciated.

legendstyler