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

橙三吉。 提交于 2019-12-02 17:38:43

问题


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

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


回答1:


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.



来源:https://stackoverflow.com/questions/5067354/how-can-i-do-a-search-for-video-on-youtube-in-my-iphone-app

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