Getting Youtube Channel Playlist using Objective-C API
Asked Answered
M

4

6

I'm trying to use Google's Objective-C Youtube APIs to fetch a youtube channel's playlist - with no luck.

-I downloaded Google's official API from: http://code.google.com/p/gdata-objectivec-client/source/browse/#svn%2Ftrunk%2FExamples%2FYouTubeSample

But the sample App doesn't really do anything - its not even an iOS sample App. Seems to be a Mac OS App. Its Read-Me file says: "This sample should automatically build and copy over the GTL.framework as part of the build-and-run process."

Ok... and then what?

How do you get this to work in an iPhone App?

I haven't found any actual instructions to make this work.

Any idea what we're supposed to do here?

Mandragora answered 7/3, 2013 at 22:9 Comment(0)
S
0

you can try source code at this path https://bitbucket.org/eivvanov/youtubedemo/overview

Shaun answered 8/3, 2013 at 4:55 Comment(0)
C
0

I have spent a day and a half trying to figure it out on how to use the MAC OSX app they have given as an example. I ended up with an iPhone app which I manage to build to get all the Uploaded video I have from YouTube.

Link: YouTubeProject

In order to make it work:

  • You have to add the GData project from google
  • In the LTMasterViewController.m-> (GDataServiceGoogleYouTube *)youTubeService: put your username and password
Chewning answered 28/3, 2013 at 9:52 Comment(1)
"Warning: Most newer Google APIs are not Google Data APIs. The Google Data APIs documentation applies only to the older APIs that are listed in the Google Data APIs directory. For information about a specific new API, see that API's documentation. For information about authorizing requests with a newer API, see Google Accounts Authentication and Authorization." developers.google.com/gdata Not sure why we should use GData if that's being replaced.Skitter
P
0

The "gdata-objectivec-client" for youtube been superseded by a JSON-API Link. Scroll down to youtube.

For supporting the JSON-API here is the details Link.

And for fetching the playlist have a look at the Link.

Peridium answered 21/10, 2013 at 20:43 Comment(0)
O
0

For total newbies who are lost : consider a sample function that will help understand the entire cycle of fetch,parse,display etc and bring youtube channel's videos to your tableview specifically. im not writing the tableview part here

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

}
Ornstead answered 2/5, 2016 at 12:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.