使用Objective-C API获取Youtube频道播放列表

时间:2013-03-07 22:09:30

标签: iphone objective-c youtube gdata

我尝试使用Google的Objective-C Youtube API来获取youtube频道的播放列表 - 没有运气。

- 我从以下网站下载了Google的官方API: http://code.google.com/p/gdata-objectivec-client/source/browse/#svn%2Ftrunk%2FExamples%2FYouTubeSample

但样本App并没有真正做任何事情 - 它甚至不是iOS样本App。似乎是一个Mac OS应用程序。它的Read-Me文件说:"这个示例应该自动构建并复制GTL.framework,作为构建和运行过程的一部分。"

好的......然后是什么?

如何在iPhone App中使用它?

我还没有找到任何实际的指示来完成这项工作。

知道我们应该在这做什么吗?

4 个答案:

答案 0 :(得分:0)

您可以在此路径中尝试源代码 https://bitbucket.org/eivvanov/youtubedemo/overview

答案 1 :(得分:0)

我花了一天半时间试图弄清楚如何使用他们提供的MAC OSX应用程序作为示例。我最终得到了一个iPhone应用程序,我设法建立这个应用程序来获取YouTube上的所有Uploaded视频。

链接:YouTubeProject

为了使其发挥作用:

  • 您必须从Google
  • 添加GData项目
  • 在LTMasterViewController.m->中(GDataServiceGoogleYouTube *)youTubeService:输入您的用户名和密码

答案 2 :(得分:0)

youtube的“gdata-objectivec-client”已被JSON-API Link取代。向下滚动到youtube。

有关支持JSON-API的详细信息,请参见Link

要获取播放列表,请查看Link

答案 3 :(得分:0)

对于迷路的新手:考虑一个示例功能,它将有助于理解整个提取,解析,显示等周期,并将youtube频道的视频专门带到您的桌面视图中。我不写这里的tableview部分

-(void)initiateRequestToYoutubeApiAndGetChannelInfo
{
NSString * urlYouCanUseAsSample = @"https://www.googleapis.com/youtube/v3/search?key={YOUR_API_KEY_WITHOUT_CURLY_BRACES}&channelId={CHANNEL_ID_YOU_CAN_GET_FROM_ADDRESS_BAR_WITHOUT_CURLY_BRACES}&part=snippet,id&order=date&maxResults=20";



NSURL *url = [[NSURL alloc] initWithString: urlYouCanUseAsSample];

// Create your request
NSURLRequest *request = [NSURLRequest requestWithURL:url];



// Send the request asynchronously remember to reload tableview on global thread
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

 // Callback, parse the data and check for errors
if (data && !connectionError) {
    NSError *jsonError;

    NSDictionary *jsonResult = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonError];

    if (!jsonError) {
    // better put a breakpoint here to see what is the result and how it is brought to you. Channel id name etc info should be there

        NSLog(@"%@",jsonResult);

    /// separating "items" dictionary and making array

        // 
id keyValuePairDict = jsonResult;
NSMutableArray * itemList = keyValuePairDict[@"items"];
        for (int i = 0; i< itemList.count; i++) {


    /// separating VIDEO ID dictionary from items dictionary and string video id
        id v_id0 = itemList[i];
        NSDictionary * vid_id = v_id0[@"id"];
        id v_id = vid_id;
        NSString * video_ID = v_id[@"videoId"];

    //you can fill your local array for video ids at this point

       //     [video_IDS addObject:video_ID];

    /// separating snippet dictionary from itemlist array
        id snippet = itemList[i];
        NSDictionary * snip = snippet[@"snippet"];

     /// separating TITLE and DESCRIPTION from snippet dictionary
        id title = snip;
        NSString * title_For_Video = title[@"title"];
        NSString * desc_For_Video = title[@"description"];

    //you can fill your local array for titles & desc at this point 

          //  [video_titles addObject:title_For_Video];
           // [video_description addObject:desc_For_Video];




     /// separating thumbnail dictionary from snippet dictionary

        id tnail = snip;
        NSDictionary * thumbnail_ = tnail[@"thumbnails"];

     /// separating highresolution url dictionary from thumbnail dictionary

        id highRes = thumbnail_;
        NSDictionary * high_res = highRes[@"high"];

     /// separating HIGH RES THUMBNAIL IMG URL from high res dictionary

        id url_for_tnail = high_res;
        NSString * thumbnail_url = url_for_tnail[@"url"];
    //you can fill your local array for titles & desc at this point

            [video_thumbnail_url addObject:thumbnail_url];


        }
     // reload your tableview on main thread   
//[self.tableView    performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
 performSelectorOnMainThread:@selector(reloadInputViews) withObject:nil waitUntilDone:NO];


  // you can log all local arrays for convenience
     //   NSLog(@"%@",video_IDS);
      //  NSLog(@"%@",video_titles);
      //  NSLog(@"%@",video_description);
      //  NSLog(@"%@",video_thumbnail_url);
    }
    else
    {
        NSLog(@"an error occurred");
    }
   }
}];

}