Retrieving YouTube Channel Downloads in Objective-C Using the v3 API

Hello, I'm trying to extract a channel object from youtube api using the google-api library in xcode, this is the code I use:

//youtubeService type is GTLServiceYouTube youtubeService = [[GTLServiceYouTube alloc] init]; youtubeService.shouldFetchNextPages = YES; //auth is the object from the authentication callback youtubeService.authorizer = auth; videoQuery = [GTLQueryYouTube queryForChannelsListWithPart:@"RayWilliamJohnson"]; videoQuery.maxResults = 20; youtubeTicket = [youtubeService executeQuery:videoQuery completionHandler: ^(GTLServiceTicket *ticket, id channel, NSError *error) { NSLog(@" %@ ", error.description); NSLog(@"WIN! : %@ ", channel); }]; 

So far I have been getting this error:

Domain error = com.google.GTLJSONRPCErrorDomain Code = -32602 "operation could not be completed. (RayWilliamJohnson)" UserInfo = 0x7532c40 {error = RayWilliamJohnson, GTLStructuredError = GTLErrorObject 0x7533d30: {message: 1iam: "1iam:" iam: Joham ]}, NSLocalizedFailureReason = (RayWilliamJohnson)}

Any idea what throws this error?

Thanks in advance for your help!

Edit : I read the documentation in classes that simply β€œdon't exist”: P and checked out other examples that also follow the same approach.

Edit2 : ok I tried the following changes, and none of them worked :(, it worked for me, using the same example in the query explorer.

 videoQuery.maxResults = 20; videoQuery.q = @"RayWilliamJohnson"; videoQuery.type = @"channel"; /*tried setting the part without calling the query method on GTLQueryYoutube but that did not work videoQuery.part = @"id";*/ videoQuery = [GTLQueryYouTube queryForChannelsListWithPart:@"id"]; //fetching only 20 items. youtubeTicket = [youtubeService executeQuery:videoQuery completionHandler: ^(GTLServiceTicket *ticket, id channel, NSError *error) { NSLog(@" %@ ", error.description); NSLog(@"WIN! : %@ ", channel); }]; 

the error is a little different, her saying that I did not specify any filters, even if I did.

 Error Domain=com.google.GTLJSONRPCErrorDomain Code=-32602 "The operation couldn't be completed. (No filter selected.)" UserInfo=0x8870250 {error=No filter selected., GTLStructuredError=GTLErrorObject 0x88707f0: {message:"No filter selected." code:-32602 data:[1]}, NSLocalizedFailureReason=(No filter selected.)} 

Edit3 : OK I changed a couple of things, at first I made a stupid mistake when I initialized my request after setting the parameters that just delete them. so the code now looks like this:

  youtubeService.authorizer = auth; videoQuery = [GTLQueryYouTube queryForChannelsListWithPart:@"id"]; videoQuery.maxResults = 1; videoQuery.q = @"RayWilliamJohnson"; videoQuery.type = @"channel"; youtubeTicket = [youtubeService executeQuery:videoQuery completionHandler:^(GTLServiceTicket *ticket, GTLYouTubeChannel *channel, NSError *error) { NSLog(@" %@ ", error.description); NSLog(@"WIN! : %@ ", channel.description); }]; 

but I still get the error " no filters specified ", which means that the variables are not set anyway ...

Edit4 : ok after so many blondes that I managed to do this, it was a query object that I initialized, I tried to use a prefix specially created to search for channels, where I’m supposed to just use queryForSearchListWithPart, so the working code looks like this:

 youtubeService.authorizer = auth; videoQuery = [GTLQueryYouTube queryForSearchListWithPart:@"id"]; videoQuery.maxResults = 1; videoQuery.q = @"RayWilliamJohnson"; youtubeTicket = [youtubeService executeQuery:videoQuery completionHandler:^(GTLServiceTicket *ticket, GTLYouTubeChannel *channel, NSError *error) { NSLog(@" %@ ", error.description); NSLog(@"WIN! : %@ ", channel.description); }]; 

and provided this result:

2012-12-12 00: 17: 21.315 Test [13099: c07] (null) 2012-12-12 00: 17: 21.316 Test [13099: c07] WIN !: GTLYouTubeSearchListResponse 0x727f6d0: {pageInfo: {totalResults, resultsPerPage} ETag : "bm4JOKyioI0quSqrxEnI8H7snE4 / A2tE7ag9HxUC5HxeD2vDlGNg5iM" "nextPageToken: type" CAEQAA ": elements" youtube # searchListResponse ": [1]}

Thanks for helping Jeff

+4
source share
3 answers

I am not an Objective-C programmer, so I cannot specifically advise on how to change the code, but this is a common problem.

It looks like you are calling the YouTube data API method v3 channels.list() , which is documented at https://developers.google.com/youtube/v3/docs/channels/list

The only parameter required is part , and I assume that the ueryForChannelsListWithPart() method takes as its one parameter. part should be set as id or id,contentDetails , as described in the docs.

Then you need to add an additional parameter to tell the API to which channel you are trying to get the information. The various options are listed in the Filters section of the documents.

The v3 API does not support stale YouTube usernames in the channels.list() call. It takes an id parameter, which corresponds to the identifiers of the channels (channels) of the YouTube channel on which you want to receive information. They usually have the form UC... , and in the case of RayWilliamJohnson , the channel identifier is UCGt7X90Au6BV8rf49BiM6Dg . (You can understand this by calling search.list() , here's an example using the API .)

Note that the channels.list () method does not actually return a list of videos. If you want to get the latest videos in a given channel, you need to make a call to channels.list() to get the corresponding playlist identifier from the contentDetails part, and then make a call to playlistItems.list() to get the video into which the playlist loads. We have an example of this in Python , but there is no end-to-end example in Objective-C.

+2
source
 service = [[GTLServiceYouTube alloc] init]; service.shouldFetchNextPages = YES; service.retryEnabled = YES; service.APIKey = @"xxxxxxxx"; GTLQueryYouTube *query = [GTLQueryYouTube queryForSearchListWithPart:@"id,snippet"]; query.maxResults = 15; query.q = YOUR_SEARCH_TEXT; query.fields = @"items(id,snippet)"; query.order = @"viewCount"; [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) { if (!error) { for (GTLYouTubeVideoListResponse *videoInfo in object) { [youtubeList addObject:videoInfo.JSON]; } NSLog(@"youtubeList count %lu",(unsigned long)youtubeList.count); NSLog(@"youtubeList %@",youtubeList); [self.tableView reloadData]; } else { NSLog(@"%@", error); } -- i'm test this currently for pagination -- GTLYouTubePlaylistItemListResponse *playlistItems = object; NSLog(@"playlistItems.nextPageToken %@",playlistItems.nextPageToken); NSLog(@"playlistItems.prevPageToken %@",playlistItems.prevPageToken); if(playlistItems.nextPageToken) { NSLog(@"new page!!!"); query.pageToken = playlistItems.nextPageToken; [self requestYoutubeVideo:withText]; } else { NSLog(@"No more pages"); } }]; 

`

+2
source

Anyone looking to find channels by id, use this

 GTLServiceYouTube *youTubeService = [[GTLServiceYouTube alloc] init]; youTubeService.APIKey = @"<YOUR_API_KEY>"; GTLQueryYouTube *channelsQuery = [GTLQueryYouTube queryForChannelsListWithPart:@"id,snippet,brandingSettings,contentDetails,invideoPromotion,statistics,status,topicDetails"]; channelsQuery.identifier = @"<CHANNEL_ID>"; [youTubeService executeQuery:channelsQuery completionHandler:^(GTLServiceTicket *ticket, GTLYouTubeChannelListResponse *channelListResponse, NSError *error) { if (error == nil) { if (channelListResponse.items.count > 0) { GTLYouTubeChannel *channel = channelListResponse.items.firstObject; NSLog(@"Got youtube channel - %@", channel); } else { NSLog(@"Cannot find channels with id %@", channelsQuery.identifier); } } else { NSLog(@"Cannot get youtube channels - %@", error); } }]; 
+1
source

All Articles