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

前端 未结 1 1452
情书的邮戳
情书的邮戳 2021-01-28 19:17

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

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

相关标签:
1条回答
  • 2021-01-28 19:24

    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 讨论(0)
提交回复
热议问题