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

痴心易碎 提交于 2019-12-02 09:39:39

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!