Google + iPhone API sign in and share without leaving app

前端 未结 5 2236
悲哀的现实
悲哀的现实 2020-11-29 20:59

I recently integrated the Google + API in my App, it was a breeze, my only problem with it, is that everything requires you to leave the app and then come back (it uses URL

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 21:25

    I hope it will help somebody. It merges Google+ and Gmail samples and completely avoids using Google SignIn Button, i.e you do not leave the app.

    Add both Google+ and Gmail API to you Google project, in your app login to google as you would to gmail using GTMOAuth2ViewControllerTouch.xib from OAuth2 and set scope to Google+:

    -(IBAction)dologin{
        NSString *scope = kGTLAuthScopePlusLogin;//Google+ scope
        GTMOAuth2Authentication * auth = [GTMOAuth2ViewControllerTouch 
        authForGoogleFromKeychainForName:kKeychainItemName
        clientID:kClientID
        clientSecret:kClientSecret];
        if ([auth refreshToken] == nil) {
        GTMOAuth2ViewControllerTouch *authController;
        authController = [[GTMOAuth2ViewControllerTouch alloc] 
        initWithScope:scope 
        clientID:kClientID 
        clientSecret:kClientSecret  
        keychainItemName:kKeychainItemName
        delegate:self
        finishedSelector:@selector(viewController:finishedWithAuth:error:)];
        [[self navigationController] pushViewController:authController animated:YES];
        }else{
        [auth beginTokenFetchWithDelegate:self didFinishSelector:@selector(auth:finishedRefreshWithFetcher:error:)];
        }
    }
    

    and RETAIN the authentication object if signed in successfully, then use that auth object when using google plus services:

    GTLServicePlus* plusService = [[[GTLServicePlus alloc] init] autorelease];
    [plusService setAuthorizer:self.auth];//!!!here use our authentication object!!!
    

    No need for GPPSignIn.

    Full write up is here: Here is Another Solution

提交回复
热议问题