我正在按照此示例https://code.google.com/p/google-api-objectivec-client/source/browse/#svn/trunk/Examples/YouTubeSample将 YouTube SDK 集成到我的 iOS 应用程序中。
以下是我完成的一些工作:
- 将 GTL.project 添加到我的项目中,并为 Header Search Path 设置源路径。
- 将 GTLTouchStaticLib 链接到 Link Binary 与我项目的库。
- 将 GTLYouTube_Sources.m 添加到我的项目中。
- 从 YouTubeSample 复制一些代码,这里是代码片段:
#import "ViewController.h"
#import "GTLYouTube.h"
#import "GTLUtilities.h"
#import "GTMHTTPUploadFetcher.h"
#import "GTMHTTPFetcherLogging.h"
#import "GTMOAuth2ViewControllerTouch.h"
.
.
- (IBAction)Login:(id)sender {
GTMOAuth2ViewControllerTouch *viewController;
viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:kGTLAuthScopeYouTube
clientID:kMyClientID
clientSecret:kMyClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[self presentViewController:viewController animated:YES completion:NULL];
}
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error == nil) {
self.youTubeService.authorizer = auth;
// [self dismissViewControllerAnimated:YES completion:NULL];
[self fetchMyChannelList];
} else {
NSLog(@"Auth failed: %@", error);
}
}
- (void)fetchMyChannelList {
NSLog(@"fetchMyChannelList");
_myPlaylists = nil;
_channelListFetchError = nil;
GTLServiceYouTube *service = self.youTubeService;
GTLQueryYouTube *query = [GTLQueryYouTube queryForChannelsListWithPart:@"contentDetails"];
query.mine = YES;
// maxResults specifies the number of results per page. Since we earlier
// specified shouldFetchNextPages=YES, all results should be fetched,
// though specifying a larger maxResults will reduce the number of fetches
// needed to retrieve all pages.
query.maxResults = 50;
// We can specify the fields we want here to reduce the network
// bandwidth and memory needed for the fetched collection.
//
// For example, leave query.fields as nil during development.
// When ready to test and optimize your app, specify just the fields needed.
// For example, this sample app might use
//
// query.fields = @"kind,etag,items(id,etag,kind,contentDetails)";
_channelListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLYouTubeChannelListResponse *channelList,
NSError *error) {
// Callback
// The contentDetails of the response has the playlists available for
// "my channel".
if ([[channelList items] count] > 0) {
GTLYouTubeChannel *channel = channelList[0];
_myPlaylists = channel.contentDetails.relatedPlaylists;
NSLog(@"_myPlaylists: %@", _myPlaylists);
}
_channelListFetchError = error;
_channelListTicket = nil;
if (_myPlaylists) {
[self fetchSelectedPlaylist];
}
[self fetchVideoCategories];
}];
}
构建并运行后,我使用我的 youtube 帐户登录,当我在页面中单击同意时,应用程序崩溃,这是错误输出:
2013-09-30 04:12:47.618 YoutubeAPITest[4153:a0b] popView
2013-09-30 04:12:48.684 YoutubeAPITest[4153:a0b] fetchMyChannelList
2013-09-30 04:12:48.685 YoutubeAPITest[4153:a0b] GTLRuntimeCommon: 意外属性 TB,D 用于我的财产
2013-09-30 04:12:48.685 YoutubeAPITest[4153:a0b] GTLRuntimeCommon:“GTLQueryYouTube”类的属性“mine”的意外返回类型类
2013-09-30 04:12:48.686 YoutubeAPITest[4153:a0b]-[GTLQueryYouTube setMine:]:无法识别的选择器发送到实例 0x1090c13e0
2013-09-30 04:12:48.689 YoutubeAPITest[4153:a0b] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[GTLQueryYouTube setMine:]:无法识别的选择器发送到实例 0x1090c13e0”
*** 首先抛出调用堆栈:
(
0 核心基础 0x0000000101a7c795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001017df991 objc_exception_throw + 43
2核心基础0x0000000101b0dbad-[NSObject(NSObject)不识别选择器:]+205
3 核心基础 0x0000000101a6e09d ___forwarding___ + 973
4 核心基础 0x0000000101a6dc48 _CF_forwarding_prep_0 + 120
5 YoutubeAPITest 0x0000000100001ae2 -[ViewController fetchMyChannelList] + 258
6 YoutubeAPITest 0x000000010000197a -[ViewController viewController:finishedWithAuth:error:] + 218
7 核心基础 0x0000000101a7222c __invoking___ + 140
8 CoreFoundation 0x0000000101a720d4 -[NSInvocation 调用] + 308
9 YoutubeAPITest 0x000000010001474d-[GTMOAuth2ViewControllerTouch 登录:finishedWithAuth:错误:] + 701
10 核心基础 0x0000000101a7222c __invoking___ + 140
11 CoreFoundation 0x0000000101a720d4 -[NSInvocation 调用] + 308
12 YoutubeAPITest 0x00000001000113cf -[GTMOAuth2SignIn invokeFinalCallbackWithError:] + 415
13 YoutubeAPITest 0x000000010001121e -[GTMOAuth2SignIn 完成SignInWithError:] + 62
14 YoutubeAPITest 0x0000000100010daa -[GTMOAuth2SignIn fetchGoogleUserInfo] + 506
15 YoutubeAPITest 0x000000010001096b -[GTMOAuth2SignIn auth:finishedWithFetcher:error:] + 251
16 核心基础 0x0000000101a7222c __invoking___ + 140
17 CoreFoundation 0x0000000101a720d4 -[NSInvocation 调用] + 308
18 YoutubeAPITest 0x000000010000df43 +[GTMOAuth2Authentication invokeDelegate:selector:object:object:object:] + 355
19 YoutubeAPITest 0x000000010000c856-[GTMOAuth2Authentication tokenFetcher:finishedWithData:error:] + 1334
20 核心基础 0x0000000101a7222c __invoking___ + 140
21 CoreFoundation 0x0000000101a720d4 -[NSInvocation 调用] + 308
22 YoutubeAPITest 0x000000010001add8 -[GTMHTTPFetcher invokeFetchCallback:target:data:error:] + 344
23 YoutubeAPITest 0x000000010001ac4c -[GTMHTTPFetcher invokeFetchCallbacksWithData:error:] + 204
24 YoutubeAPITest 0x000000010001c165-[GTMHTTPFetcher connectionDidFinishLoading:] + 1333
25 基础 0x00000001014d103b __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 48
26 基础 0x000000010138476b -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 210
27 基础 0x000000010138467c -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 69
28 CFNetwork 0x00000001068c88b7 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
29 CFNetwork 0x00000001068c6a82 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 84
30 CFNetwork 0x000000010690a024 ___ZNK17CoreSchedulingSet13_performAsyncEPKcU13block_pointerFvvE_block_invoke + 25
31 核心基础 0x0000000101a230b4 CFArrayApplyFunction + 68
32 CFNetwork 0x0000000106839d7b _ZN19RunloopBlockContext7performEv + 115
33 CFNetwork 0x0000000106839bc1 _ZN17MultiplexerSource7performEv + 247
34 CFNetwork 0x00000001068399e4 _ZN17MultiplexerSource8_performEPv + 72
35 核心基础 0x0000000101a0be61 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
36 核心基础 0x0000000101a0b732 __CFRunLoopDoSources0 + 242
37 核心基础 0x0000000101a275bf __CFRunLoopRun + 767
38 核心基础 0x0000000101a26ed3 CFRunLoopRunSpecific + 467
39 图形服务 0x0000000103b1d3a4 GSEventRunModal + 161
40 UIKit 0x0000000100447a63 UIApplicationMain + 1010
41 YoutubeAPITest 0x0000000100008c13 主要 + 115
42 libdyld.dylib 0x00000001020ef7e1 开始 + 0
43 ???0x0000000000000001 0x0 + 1
)
libc++abi.dylib:以 NSException 类型的未捕获异常终止
(lldb)
似乎身份验证成功,但 fetchMyChannelList 失败:为我的查询属性设置值时发生错误。我已经重新检查了所有步骤,但无法找出问题所在,请帮助。