How can I do a search for video on youtube in my iPhone app?

551 views Asked by At

In my iPhone application, I want to do a search for video on youtube.

How can I do this (with the GData API)?

1

There are 1 answers

4
Walter On BEST ANSWER

You do it the same as you would ask for any other data. If I wanted to search for youtube videos from my iPhone application, I would create a request to youtube that looked like this:

-(void)fetchYoutubeData:(NSString *)myQuery{
//where myQuery is the string to search for
//it needs to be encoded to stick in the url so Jimi%20Hendrix instead
///of Jimi Hendrix
NSError *err = [[[NSError alloc] init] autorelease];
NSString *myRequest = [NSString stringWithFormat:@"http://gdata.youtube.com/feeds/api/videos?q=%@&max-results=5",myQuery]; 
NSURL *url = [NSURL URLWithString:myRequest];  
NSString *myYouTubeData = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&err];
if(err.code != 0) {
//HANDLE ERROR HERE
}
//Do Something with myYouTubeData here
}

You will need to parse the myYouTubeData string that you get back. The complete guide on how to structure your query can be found at the YouTube API webpage.