Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Plus Login

Scenario: Login to App via Google+ Login

Implementation:

- (void)viewDidLoad {
    [super viewDidLoad];

    GPPSignIn *aGPSSignIn = [GPPSignIn sharedInstance];
    aGPSSignIn.scopes = @[ kGTLAuthScopePlusLogin, kGTLAuthScopePlusUserinfoEmail, kGTLAuthScopePlusUserinfoProfile, kGTLAuthScopePlusMe];
    aGPSSignIn.shouldFetchGoogleUserEmail = YES;
    aGPSSignIn.shouldFetchGooglePlusUser =YES;
    aGPSSignIn.homeServerClientID = kClientID;
    aGPSSignIn.clientID = kClientID;
    aGPSSignIn.delegate = self;
    if (![aGPSSignIn trySilentAuthentication]) {
        [self showLoginButton];
    }
}

- (void)showLoginButton {
    if (!self.signInButton) {        
        self.signInButton = [GPPSignInButton buttonWithType:UIButtonTypeCustom];
        [self.signInButton setFrame:CGRectMake(60, 100, 200, 40)];
    }
    [self.view addSubview:self.signInButton];
}

#pragma mark - GPPSignInDelegate

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth error: (NSError *) error {
    NSString *anAccessToken = auth.accessToken;
    NSLog(@"googleAccessToken:%@",anAccessToken);
}

- (void)didDisconnectWithError:(NSError *)iError {
    if (iError) {
        NSLog(@"Error:%@", iError);
    }
}

Note: - (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication:(NSString *)sourceApplication annotation: (id)annotation is handled in the AppDelegate.

Issue:

  • The Google+ login works perfectly fine when the user clicks on the Google SignIn Button and is navigated to the Safari. A valid AccessToken is received in my app.
  • However, if the Google+ app is available on the iPhone, the user is navigated to the Google+ app but on Login no AccessToken is received. I get an Error.

Error:

Received error Error Domain=com.google.GooglePlusPlatform Code=-1 "The operation couldn’t be completed. (com.google.HTTPStatus error 400.)" UserInfo=0x15d95f90 {NSLocalizedDescription=The operation couldn’t be completed. (com.google.HTTPStatus error 400.)} and auth object (null)

It will be very helpful if someone can guide me in solving this issue. Thanks.

like image 728
Nishi Avatar asked Nov 05 '14 13:11

Nishi


People also ask

How do I log into Google+?

In your browser, type: plus.google.com and sign up with your Google account. If you haven't created a Google account, you will be redirected to the sign up flow.

What is G+ account?

Google+ (pronounced Google plus) is a Google social networking platform. The Google+ design team sought to replicate the way people interact offline more closely than is the case in other social networking services, such as Facebook and Twitter. The project's slogan is “Real-life sharing rethought for the web.”

Is Google Plus still available?

Google Plus, the company's failed social network, is officially gone as of today. After Google Plus personal accounts were shut down last year, Google announced that it would be replacing the social network for enterprise users with Google Currents.

How do I sign up for Google Plus?

In your browser, type: plus.google.com and sign up with your Google account. If you haven't created a Google account, you will be redirected to the sign up flow.

Why do I need to sign in to my Google account?

When you sign in to your Google Account, you can see and manage your info, activity, security options, and privacy preferences to make Google work better for you. You can review and adjust some privacy options now, and find even more controls if you sign in or create an account. Learn more. Sign in.

What are the benefits of having a Google account?

Your Google Account automatically protects your personal information and keeps it private and safe. Every account comes with powerful features like spam filters that block 99.9% of dangerous emails before they ever reach you, and personalized security notifications that alert you of suspicious activity and malicious websites.

Can I use an app password to sign in to Google?

On some apps and devices, you can use an app password to sign in to your Google Account.


1 Answers

Please set the URL scheme in project.

steps:

  • Login your developer account
  • select your project
  • select APIs & auth from sidebar
  • select Credentials
  • copy the 'REDIRECT URIS' and 'BUNDLE ID'
  • Oen Xcode project
  • select project target
  • select 'Info'
  • expand URL types
  • paste the 'BUNDLE ID' in Identifier area
  • paste the 'REDIRECT URIS' in the URL Schemes area

If it is not working try by replacing the 'REDIRECT URIS' with 'BUNDLE ID', i.e., the Identifier and URL Schemes are same.

Hope this may help you

like image 113
Neenu Avatar answered Oct 17 '22 15:10

Neenu