Exception when trying to fetch channelId using the youtube api in objective c -
i trying fetch youtube channel id using google-api-objectivec-client. problem having reason receiving exception when trying access channelid. code using:
gtlserviceyoutube *service = [[gtlserviceyoutube alloc] init]; service.apikey = _my_api_key_; gtlqueryyoutube *query = [gtlqueryyoutube queryforsearchlistwithpart:@"id"]; query.q = @"google"; query.type = @"channel"; query.maxresults = 1; gtlserviceticket *ticket = [service executequery:query completionhandler:^(gtlserviceticket *ticket, id object, nserror *error) { if (error == nil) { gtlyoutubesearchlistresponse *products = object; (id item in products.items) { gtlyoutubesearchresult *result = item; nslog(@"identifier:%@",result.identifier); gtlyoutuberesourceid* resourceid = result.identifier; nslog(@"kind:%@",resourceid.kind); nslog(@"channel:%@",resourceid.channelid); } }else{ nslog(@"error: %@", error.description); } }];
the output when running code is:
2013-04-05 11:37:12.615 youtest[21704:11303] identifier:gtlyoutubechannel 0x7233b00: {kind:"youtube#channel" channelid?:"uck8sqmjbp8gcxrotxwbpyea"} 2013-04-05 11:37:12.617 youtest[21704:11303] kind:youtube#channel 2013-04-05 11:37:12.617 youtest[21704:11303] -[gtlyoutubechannel channelid]: unrecognized selector sent instance 0x7233b00 2013-04-05 11:37:12.618 youtest[21704:11303] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[gtlyoutubechannel channelid]: unrecognized selector sent instance 0x7233b00'
so implementation crashes on point trying access channelid of resourceid. documentation understood channelid should there type of resourceid youtube#channel. channelid can off course parsed result.identifier string printing, since there property channelid prefer using that.
any ideas wrong code?
there indeed bug in google libraries. solved problem accessing json string directly , parsing of nsstring+sbjson.h class, in example.
#import "nsstring+sbjson.h" ... gtlyoutuberesourceid *resource = channel.snippet.resourceid; nsdictionary *jsonobject = [resource.jsonstring jsonvalue]; nsstring *channelid = [jsonobject valueforkey:@"channelid"];
Comments
Post a Comment