开发者

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

开发者 https://www.devze.com 2023-02-12 03:47 出处:网络
In my iPhone applica开发者_运维百科tion, I want to do a search for video on youtube. How can I do this (with the GData API)?You do it the same as you would ask for any other data. If I wanted to sear

In my iPhone applica开发者_运维百科tion, I want to do a search for video on youtube.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消