使用API的v3检索Objective

编程入门 行业动态 更新时间:2024-10-26 16:23:15
使用API的v3检索Objective-C中的YouTube频道上传(Retrieving YouTube Channel Uploads in Objective-C using v3 of the API)

您好,我正在尝试使用xcode中的google-api库从youtube api获取频道对象,这是我正在使用的代码:

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

到目前为止,我一直收到这个错误:

错误域= com.google.GTLJSONRPCErrorDomain代码= -32602“操作无法完成。(RayWilliamJohnson)”UserInfo = 0x7532c40 {error = RayWilliamJohnson,GTLStructuredError = GTLErrorObject 0x7533d30:{message:“RayWilliamJohnson”代码:-32602数据: [1]},NSLocalizedFailureReason =(RayWilliamJohnson)}

知道是什么引发了这个错误吗?

先谢谢您的帮助!

编辑 :我已经阅读了几个“不存在”的类中的文档:P并检查了其他遵循相同方法的示例。

编辑2 :好的我已经尝试了以下更改,但没有一个工作:(,它适用于我在查询资源管理器上使用相同的示例。

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

错误略有不同,它说我没有指定任何过滤器,即使我做了。

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.)}

编辑3 :好的我已经改变了一些事情,首先我犯了一个愚蠢的错误,我在设置简单删除它们的参数后初始化我的查询。 所以代码现在看起来像这样:

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

但我仍然得到' 没有指定过滤器 '的错误,这意味着变量没有设置任何方式......

编辑4 :好吧经过这么多金发时刻我设法做到这一点,这是我正在初始化的查询对象,我试图使用专门为频道查找做的前缀,我应该只使用queryForSearchListWithPart ,所以有效的代码如下所示:

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

并提供了这个结果:

2012-12-12 00:17:21.315测试[13099:c07](null)2012-12-12 00:17:21.316测试[13099:c07]赢! :GTLYouTubeSearchListResponse 0x727f6d0:{pageInfo:{totalResults,resultsPerPage} etag:“”bm4JOKyioI0quSqrxEnI8H7snE4 / A2tE7ag9HxUC5HxeD2vDlGNg5iM“”nextPageToken:“CAEQAA”kind:“youtube#searchListResponse”items:[1]}

谢谢你的帮助杰夫

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

//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've been getting this error:

Error Domain=com.google.GTLJSONRPCErrorDomain Code=-32602 "The operation couldn’t be completed. (RayWilliamJohnson)" UserInfo=0x7532c40 {error=RayWilliamJohnson, GTLStructuredError=GTLErrorObject 0x7533d30: {message:"RayWilliamJohnson" code:-32602 data:[1]}, NSLocalizedFailureReason=(RayWilliamJohnson)}

Any idea what is throwing this error?

Thanks in advance for the help!

Edit: I've read the documentation in the classes which simply 'does not exist' :P and checked the other examples that also follows the same approach.

Edit2: ok I've tried the following changes and none of them worked :(, it worked for me using the same example on 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 slightly different, its saying that I havent specified any filters even though 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've changed couple of things, first I was making a stupid mistake where I was initializing my query after setting parameters which simply removes 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'm still getting the error of 'no filters specified' which means that variables are not set either way...

Edit4: ok after so many blonde moments I managed to do this, it was the query object I was initializing, I was trying to use the prefixed one that is specifically made for channel lookups where I'm supposed to just use the queryForSearchListWithPart, so the code that worked 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:"CAEQAA" kind:"youtube#searchListResponse" items:[1]}

Thanks for your help Jeff

最满意答案

我不是Objective-C程序员,因此我不能特别建议如何修改代码,但这是一般性问题。

您好像在调用YouTube Data API v3 channels.list()方法,该方法记录在https://developers.google.com/youtube/v3/docs/channels/list

一个必需参数是part ,我假设ueryForChannelsListWithPart()方法作为其一个参数。 part应设置为id或id,contentDetails ,如文档中所述。

然后,您需要添加一个额外的参数来告诉API您尝试检索哪些信道的信息。 各种选项列在文档的“过滤器”部分中。

API的v3不支持在channels.list()调用中指定旧版YouTube用户名。 它确实包含一个id参数,该参数对应于您要检索其信息的频道的YouTube频道ID。 这些通常是UC...的形式,而在RayWilliamJohnson的情况下,通道ID是UCGt7X90Au6BV8rf49BiM6Dg 。 (您可以通过search.list()调用来解决这个问题;这是使用API​​ Explorer的示例 。)

请注意,channels.list()方法实际上并不返回视频列表。 如果要检索给定频道中的最新视频,则需要进行channels.list()调用以从contentDetails部分获取相应的上传播放列表ID,然后进行playlistItems.list()调用以获取其中的视频上传了播放列表。 我们有一个在Python中执行此操作的示例,但目前还没有Objective-C中的端到端示例。

I'm not an Objective-C programmer, so I can't specifically advise on how to modify your code, but here's the general issue.

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

The one required parameter is part, and I assume that's what the ueryForChannelsListWithPart() method takes in as its one parameter. part should be set to something like id or id,contentDetails, as explained in the docs.

You then need to add in an additional parameter to tell the API which channel you're trying to retrieve information about. The various options are listed in the "Filters" section of the docs.

v3 of the API doesn't support specifying legacy YouTube usernames in a channels.list() call. It does take in a id parameter, which corresponds to the YouTube channel id(s) of the channel(s) you want to retrieve information about. These are usually of the form UC..., and in the case of RayWilliamJohnson the channel id is UCGt7X90Au6BV8rf49BiM6Dg. (You can figure this out via a search.list() call; here's an example using the API Explorer.)

Please note that the channels.list() method doesn't actually return a list of videos. If you want to retrieve the most recent videos in a given channel, you need to make a channels.list() call to obtain the corresponding uploads playlist id from the contentDetails part, and then make a playlistItems.list() call to get the videos in that uploads playlist. We have an example of doing this in Python, but no end-to-end example in Objective-C yet.

更多推荐

本文发布于:2023-07-15 19:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:API   Objective

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!