Reputation: 889
I'm following this example https://code.google.com/p/google-api-objectivec-client/source/browse/#svn/trunk/Examples/YouTubeSample to integrate YouTube SDK into my iOS app.
Here are some jobs I have done:
- Add the GTL.project into my project and set the source path for Header Search Path.
- Link the GTLTouchStaticLib to Link Binary with Libraries of my project.
- Add GTLYouTube_Sources.m into my project.
- Copy some codes from YouTubeSample, here is the code snippet:
#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];
}];
}
After build and run, I sign in with my youtube account, when I click Agree in the page, the app crashes, here is the error output:
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: unexpected attributes TB,D for property mine 2013-09-30 04:12:48.685 YoutubeAPITest[4153:a0b] GTLRuntimeCommon: unexpected return type class for property "mine" of class "GTLQueryYouTube" 2013-09-30 04:12:48.686 YoutubeAPITest[4153:a0b] -[GTLQueryYouTube setMine:]: unrecognized selector sent to instance 0x1090c13e0 2013-09-30 04:12:48.689 YoutubeAPITest[4153:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GTLQueryYouTube setMine:]: unrecognized selector sent to instance 0x1090c13e0' *** First throw call stack: ( 0 CoreFoundation 0x0000000101a7c795 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001017df991 objc_exception_throw + 43 2 CoreFoundation 0x0000000101b0dbad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x0000000101a6e09d ___forwarding___ + 973 4 CoreFoundation 0x0000000101a6dc48 _CF_forwarding_prep_0 + 120 5 YoutubeAPITest 0x0000000100001ae2 -[ViewController fetchMyChannelList] + 258 6 YoutubeAPITest 0x000000010000197a -[ViewController viewController:finishedWithAuth:error:] + 218 7 CoreFoundation 0x0000000101a7222c __invoking___ + 140 8 CoreFoundation 0x0000000101a720d4 -[NSInvocation invoke] + 308 9 YoutubeAPITest 0x000000010001474d -[GTMOAuth2ViewControllerTouch signIn:finishedWithAuth:error:] + 701 10 CoreFoundation 0x0000000101a7222c __invoking___ + 140 11 CoreFoundation 0x0000000101a720d4 -[NSInvocation invoke] + 308 12 YoutubeAPITest 0x00000001000113cf -[GTMOAuth2SignIn invokeFinalCallbackWithError:] + 415 13 YoutubeAPITest 0x000000010001121e -[GTMOAuth2SignIn finishSignInWithError:] + 62 14 YoutubeAPITest 0x0000000100010daa -[GTMOAuth2SignIn fetchGoogleUserInfo] + 506 15 YoutubeAPITest 0x000000010001096b -[GTMOAuth2SignIn auth:finishedWithFetcher:error:] + 251 16 CoreFoundation 0x0000000101a7222c __invoking___ + 140 17 CoreFoundation 0x0000000101a720d4 -[NSInvocation invoke] + 308 18 YoutubeAPITest 0x000000010000df43 +[GTMOAuth2Authentication invokeDelegate:selector:object:object:object:] + 355 19 YoutubeAPITest 0x000000010000c856 -[GTMOAuth2Authentication tokenFetcher:finishedWithData:error:] + 1334 20 CoreFoundation 0x0000000101a7222c __invoking___ + 140 21 CoreFoundation 0x0000000101a720d4 -[NSInvocation invoke] + 308 22 YoutubeAPITest 0x000000010001add8 -[GTMHTTPFetcher invokeFetchCallback:target:data:error:] + 344 23 YoutubeAPITest 0x000000010001ac4c -[GTMHTTPFetcher invokeFetchCallbacksWithData:error:] + 204 24 YoutubeAPITest 0x000000010001c165 -[GTMHTTPFetcher connectionDidFinishLoading:] + 1333 25 Foundation 0x00000001014d103b __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 48 26 Foundation 0x000000010138476b -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 210 27 Foundation 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 CoreFoundation 0x0000000101a230b4 CFArrayApplyFunction + 68 32 CFNetwork 0x0000000106839d7b _ZN19RunloopBlockContext7performEv + 115 33 CFNetwork 0x0000000106839bc1 _ZN17MultiplexerSource7performEv + 247 34 CFNetwork 0x00000001068399e4 _ZN17MultiplexerSource8_performEPv + 72 35 CoreFoundation 0x0000000101a0be61 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 36 CoreFoundation 0x0000000101a0b732 __CFRunLoopDoSources0 + 242 37 CoreFoundation 0x0000000101a275bf __CFRunLoopRun + 767 38 CoreFoundation 0x0000000101a26ed3 CFRunLoopRunSpecific + 467 39 GraphicsServices 0x0000000103b1d3a4 GSEventRunModal + 161 40 UIKit 0x0000000100447a63 UIApplicationMain + 1010 41 YoutubeAPITest 0x0000000100008c13 main + 115 42 libdyld.dylib 0x00000001020ef7e1 start + 0 43 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
It seems like the Authentication is succeed, but fetchMyChannelList failed: the error occur when setting value for mine propety of query. I have recheck all the steps but can't figure out what's wrong, please help.
Upvotes: 1
Views: 1717
Reputation: 21
I just ran into the same problem using the Google Calendar api.
GTLRuntimeCommon: unexpected attributes TB,D for property singleEvents
If your using the the Google-API-Client found on Cocoa Pods then this might be the cause. I found that the cocoapod is slightly outdated and crashes when setting booleans in queries on 64 bit iPhones. The source found here https://code.google.com/p/google-api-objectivec-client/ has been patched with a fix.
In case your curious here is the commit where it was patched https://code.google.com/p/google-api-objectivec-client/source/detail?r=364
Upvotes: 2