Google Drive: Authenticated, but not Authenticated?

55 views
Skip to first unread message

ProgrammersWeb

unread,
Mar 18, 2014, 12:37:59 AM3/18/14
to gdata-objec...@googlegroups.com
Hello,

I am trying to build a simple Google Drive test application to upload a file. The project is designed to run on OS X and is written in Objective-C.

I begin by asking for a sign in:

if(![self isAuthorized]){

    GTMOAuth2WindowController *windowController;

    windowController = [[[GTMOAuth2WindowController alloc] initWithScope:scope clientID:kClientID clientSecret:kClientSecret          keychainItemName:kKeychainItemName resourceBundle:nil] autorelease];

    [windowController signInSheetModalForWindow:self.window

                                 delegate:self

                         finishedSelector:@selector(windowController:finishedWithAuth:error:)];

    }


the finished selector is defined as:


- (void)windowController:(GTMOAuth2WindowController *)viewController

      finishedWithAuth:(GTMOAuth2Authentication *) auth

                 error:(NSError *)error {

    if (error != nil) {

        NSLog(@"Authenticated failed");

        NSLog(@"Error code: %@", [error localizedDescription]);

    } else {

        NSLog(@"Authentication succeeded");

        

         [[self driveService]setAuthorizer:auth];

    }

}


After this process is finished. I am told that authentication has succeeded as there is no error given.


When the user clicks a button to upload a file I first double check to make sure the authentication is still valid:


-(BOOL)isAuthorized{


    return [((GTMOAuth2Authentication*)self.driveService.authorizer) canAuthorize];

    

}


Instead of 1 (TRUE) being returned I get a 0 (FALSE). Why does the authentication become invalid?


I looked at the refresh token myself to see if something was wonky with canAuthorize like this:


   NSString *refreshToken =  ((GTMOAuth2Authentication*)(self.driveService.authorizer)).refreshToken;

    NSLog(@"Refresh Token: %@",refreshToken);


The refresh token was empty, so something is wrong with the authorization.


What am I doing incorrectly?


Any help is appreciated greatly!!


Thanks!

Greg Robbins

unread,
Mar 19, 2014, 8:43:11 PM3/19/14
to gdata-objec...@googlegroups.com
I don't see an obvious cause of the service losing the auth object or the auth object losing the refresh token. I suspect it's really a different drive service instance, or else some other method cleared its authorizer pointer.

Incidentally, this mailing list is for the client library for older XML APIs. The discussion group for the Objective-C client library for JSON APIs is http://groups.google.com/group/google-api-objectivec-client
Reply all
Reply to author
Forward
0 new messages