I'm building a small Instagram client for personal use on Mac OSX. I'm currently using gtm-oauth2 to obtain an oauth2 token from Instagram. I'm following the guide provided with the source to obtain this token. I've got it 90% working. The webView loads with the authentication details, and I can enter my account and the permissions screen comes up asking if I would like to grant my application access. The issue I'm running into is that after authenticating, regardless of whether I "Allow" or "Cancel", the application crashes with no stack trace or additional information. The only info I get regarding the exception is "Thread 1: EXC_BAD_ACCESS (code = 1, address=0x4c1)" and it appears that the thread is doing something to do with the WebCore::ResourceLoader, but it's a bunch of ASM so I've got no idea where this call is actually occurring. Perhaps I'm not calling the windowController properly? I've got my code included below.
- (void)signIntoInstagram {
NSURL *tokenURL =[NSURL URLWithString:kTOKENIURl];
// Set up the OAuth request
GTMOAuth2Authentication *auth = [GTMOAuth2Authentication
authenticationWithServiceProvider:@"Instagram"
tokenURL:tokenURL
redirectURI:kREDIRECTURI
clientID:KCLIENTID
clientSecret:KCLIENTSERCRET
];
// Specify the appropriate scope string, if any, according to the service's API documentation
auth.scope = @"basic";
NSURL *authURL = [NSURL URLWithString:KAUTHURL];
// Display the authentication view
GTMOAuth2WindowController *windowController;
windowController = [GTMOAuth2WindowController controllerWithAuthentication:auth
authorizationURL:authURL
keychainItemName:kKeychainItemName
resourceBundle:nil];
// optional: display some html briefly before the sign-in page loads
NSString *html = @"<html><body><div align=center>Loading sign-in page...</div></body></html>";
[windowController setInitialHTMLString:html];
[windowController signInSheetModalForWindow:_window
delegate:self
finishedSelector:@selector(windowController:finishedWithAuth:error:)];}
If I insert a breakpoint within the windowController:finishedWithAuth:error: method, the application is reaching it. However, it still crashes after I run through, which to me seems like some sort of asynchronous operation causing the error. Hopefully I'm just missing something simple here; I can't imagine there is a major flaw in Google's OAuth project.
I found this on a Google group after having the same problem https://groups.google.com/forum/#!msg/gtm-oauth/N6jlOpL9k5g/n4TdrTJyxzcJ . There is also an issue logged for it https://code.google.com/p/gtm-oauth/issues/detail?id=11
Basically I commented out line 331 of GTMOAuth2WindowController.m and it worked. You can also add your vote to the issue and maybe Google will fix it.