2013-03-07 31 views
6

Tôi đang cố gắng sử dụng API Youtube mục tiêu của Google để tìm danh sách phát của kênh youtube - không có may mắn.Tạo danh sách phát Kênh Youtube bằng cách sử dụng API mục tiêu-C

-Tôi tải API chính thức của Google từ: http://code.google.com/p/gdata-objectivec-client/source/browse/#svn%2Ftrunk%2FExamples%2FYouTubeSample

Nhưng mẫu App không thực sự làm bất cứ điều gì - thậm chí không phải là một mẫu iOS của App. Có vẻ là một ứng dụng Mac OS. Tệp Read-Me của nó cho biết: "Mẫu này sẽ tự động xây dựng và sao chép trên GTL.framework như là một phần của quá trình xây dựng và chạy."

Ok ... và sau đó là gì?

Bạn làm cách nào để hoạt động trong ứng dụng iPhone?

Tôi chưa tìm thấy bất kỳ hướng dẫn thực tế nào để thực hiện công việc này.

Bất kỳ ý tưởng nào chúng tôi phải làm ở đây?

Trả lời

0

Tôi đã dành một ngày rưỡi cố gắng tìm nó ra làm thế nào để sử dụng ứng dụng MAC OSX họ đã đưa ra làm ví dụ. Tôi đã kết thúc với một ứng dụng iPhone mà tôi quản lý để xây dựng để có được tất cả video đã tải lên mà tôi có từ YouTube.

Link: YouTubeProject

Để làm cho nó hoạt:

  • Bạn phải bổ sung dự án GData từ google
  • Trong LTMasterViewController.m-> (GDataServiceGoogleYouTube *) youTubeService: đặt tên người dùng và mật khẩu của bạn
+0

"Cảnh báo: Các API Google API mới hơn chỉ áp dụng cho các API cũ hơn được liệt kê trong thư mục API dữ liệu của Google. một API mới cụ thể, xem tài liệu API đó. Để biết thông tin về việc cấp phép các yêu cầu với API mới hơn, hãy xem Xác thực và cấp phép tài khoản Google. " https://developers.google.com/gdata/ Không chắc chắn lý do chúng tôi nên sử dụng GData nếu nó được thay thế. – Zsolt

0

"gdata-objectivec-client" dành cho youtube được thay thế bởi JSON-API Link . Cuộn xuống youtube.

Để hỗ trợ JSON-API ở đây là chi tiết Link.

Và để tìm nạp danh sách phát, hãy xem Link.

0

Đối với tổng số người mới bị mất: hãy xem xét chức năng mẫu giúp hiểu toàn bộ chu kỳ tìm nạp, phân tích cú pháp, hiển thị v.v ... và đưa video của kênh youtube vào chế độ xem bảng của bạn. im không viết phần xem bảng tại đây

-(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"); 
    } 
    } 
}]; 

} 
Các vấn đề liên quan