您好,我正在尝试使用 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)”用户信息 = 0x7532c40 {error = RayWilliamJohnson,GTLStructuredError = GTLErrorObject 0x7533d30:{消息:“RayWilliamJohnson”代码:-32602 数据: [1]}, NSLocalizedFailureReason=(RayWilliamJohnson)}
知道是什么引发了这个错误吗?
在此先感谢您的帮助!
编辑:我已经阅读了“不存在”的类中的文档:P 并检查了也遵循相同方法的其他示例。
Edit2:好的,我尝试了以下更改,但没有一个起作用:(,它在查询资源管理器上使用相同的示例对我有用。
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.)}
Edit3:好的,我已经改变了几件事,首先我犯了一个愚蠢的错误,我在设置参数后初始化我的查询,这只是删除了它们。所以代码现在看起来像这样:
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);
}];
但我仍然收到'没有指定过滤器'的错误,这意味着变量没有设置任何一种方式......
Edit4:好吧,经过这么多金发女郎的时刻,我设法做到了,这是我正在初始化的查询对象,我试图使用专门为频道查找制作的前缀对象,我应该只使用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]}
感谢您的帮助杰夫