您好,我試圖使用xcode中的google-api庫從youtube API獲取頻道對象,這是我正在使用的代碼:使用API的v3在Objective-C中檢索YouTube頻道上傳使用API的v3獲取YouTube頻道上傳
//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);
}];
到目前爲止,我已經收到此錯誤:
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)}
任何想法拋出這個錯誤?
在此先感謝您的幫助!
編輯: 我讀過的文件中,根本「不存在」的類: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 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]}
感謝您的幫助傑夫
很高興聽到你有事情現在的工作!我們確實需要獲得一些「官方」的Objective-C示例代碼。 –
現在有一個適用於YouTube庫的Objective-C示例:https://code.google.com/p/google-api-objectivec-client/source/browse/trunk/Examples/YouTubeSample/YouTubeSampleWindowController.m – grobbins