1

I'm developing an application using Xamarin.Android.

I need to enable login with Facebook and Google and I choose to use the Xamarin.Auth component. I got it work with facebook but I have some issue with Google.

This is my code:

        var auth = new OAuth2Authenticator (
            clientId: "myId.apps.googleusercontent.com",
            clientSecret: "mysecred",
            scope: "openid",
            authorizeUrl: new Uri ("https://accounts.google.com/o/oauth2/auth"),
            redirectUrl: new Uri ("myredirect:oob"),
            accessTokenUrl: new Uri ("https://accounts.google.com/o/oauth2/token"),
            getUsernameAsync: null
        ); 

        activity.StartActivity (auth.GetUI (activity));

        auth.Completed += (sender, e) => {
            Console.WriteLine (e.IsAuthenticated);
        };

Is this way the Google Activity is displayed, and I can insert my Username and password. But when I click the google login button I get a message like this:

google auth please copy this code switch to your application and paste it there [code]

What I have to do with that code? I just need to get the user name/lastname/email/id.

Thanks a lot!

2
  • have you got any work around for this problem? Commented Sep 2, 2014 at 11:34
  • @user3471528, did you get the solution for this Commented Oct 25, 2017 at 19:12

1 Answer 1

3

Bellow steps worked for me.

1.register in google developer console as webapplication instead of installed application(android)* provide the redirect url with valid url ("http://abcd.com/xyz.aspx") same should be used in the application code.

2.on authentication complete it will return access_token

3.by using the access_token make the REST request to get user complete information (https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessTokenValue + “.)

4.Deserialize the json response to get information in object.

check the source code :http://appliedcodelog.blogspot.in/2015/08/login-by-google-account-integration-for.html

Sign up to request clarification or add additional context in comments.

7 Comments

Hi Suchit, Last 2 day I am trying to use your code to make Google Plus Login in Xamarin Android. But I failed. I have looked your article, Xamarin Form discussion and try each and every thing but still facing issue. Please help.
In step 3: When I try to access user information using access token then 403 error occur in response. JSON like this: "code": 403, "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
I have also tried to make new client Id but it still showing same error
Ensure that access token has not been expired.
Today when I tired it shows : code": 401, "message": "Invalid Credentials"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.