2013-03-07 12 views
6

Sto provando a utilizzare le API Youtube di Objective-C di Google per recuperare la playlist di un canale di YouTube - senza fortuna.Ottenere playlist del canale Youtube usando l'API Objective-C

-I scaricato API ufficiale di Google da: http://code.google.com/p/gdata-objectivec-client/source/browse/#svn%2Ftrunk%2FExamples%2FYouTubeSample

Ma il campione App in realtà non fa nulla - non è nemmeno un campione di iOS App. Sembra essere un'app per Mac OS. Il suo file Leggimi dice: "Questo esempio dovrebbe creare e copiare automaticamente su GTL.framework come parte del processo build-and-run."

Ok ... e poi?

Come si ottiene questo funzionamento in un'app per iPhone?

Non ho trovato alcuna istruzione effettiva per farlo funzionare.

Qualche idea di cosa dovremmo fare qui?

risposta

0

ho trascorso un giorno e mezzo cercando di capire su come utilizzare l'applicazione MAC OSX hanno dato come esempio. Ho finito con un'applicazione per iPhone che riesco a creare per ottenere tutti i video caricati che ho da YouTube.

Link: YouTubeProject

Al fine di farlo funzionare:

  • Si deve aggiungere il progetto GData da google
  • Nel LTMasterViewController.m-> (GDataServiceGoogleYouTube *) youTubeService: put il tuo nome utente e password
+0

". Attenzione: La maggior parte dei più recenti API di Google non sono le API di Google di dati La documentazione API dati di Google è valida solo per le API più anziani che sono elencati nella directory API dati di Google Per informazioni su. una nuova API specifica, consulta la documentazione dell'API. Per informazioni sull'autorizzazione delle richieste con una nuova API, consulta Autenticazione e autorizzazione di Google Account. " https://developers.google.com/gdata/ Non sono sicuro del motivo per cui dovremmo utilizzare GData se questo viene sostituito. – Zsolt

0

Il "gdata-objectivec-client" per youtube è stato sostituito da una JSON-API Link . Scorri fino a YouTube.

Per supportare la JSON-API ecco i dettagli Link.

E per il recupero della playlist dare un'occhiata allo Link.

0

Per i neofiti totali che si sono persi: prendere in considerazione una funzione di esempio che aiuterà a comprendere l'intero ciclo di recupero, analisi, visualizzazione ecc. E di portare i video del canale di YouTube alla tabella specificatamente. im non scrivendo la parte Tableview qui

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

} 
Problemi correlati