3

I am developing an app in NativeScript 2.0 that authenticates an user by Google's Sign-In.

I also have a backend that checks the logged in user. For this I need an access token to access email and some profile data like display name and photo (via https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=<ACCESS_TOKEN_FROM_APP>).

My Android implementation looks like this:

var app = require("application");
var context = app.android.context;

var options = new com.google.android.gms.auth.api.signin.GoogleSignInOptions.Builder(com.google.android.gms.auth.api.signin.GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestEmail()
    .requestProfile()

     // get access token
    .requestServerAuthCode('MY_CLIENT_ID.apps.googleusercontent.com', false)

    .build();

In my activity result the GoogleSignInResult tells me that the operation was NOT successful (status code 12501):

activity.onActivityResult = function(requestCode, resultCode, data) {
    var signInResult = com.google.android.gms.auth.api.Auth.GoogleSignInApi.getSignInResultFromIntent(data);
    if (!signInResult.isSuccess()) {
        // code goes here

        // 12501
        var statusCode = signInResult.getStatus().getStatusCode();
    }
}

As I learned from here I have to create a special client ID / API key for my app and have to include the google-services.json into a sub folder of my Android Studio project.

In debug environment I used the SHA-1 key from by debug.keystore file of my home folder.


My question:

What is the right way to use the Google Sign-in in a NativeScript project?

Community
  • 1
  • 1
  • How did you get this `com.google.android.gms.auth.api.signin.GoogleSignInOptions.Builder` to work? I keep getting `cannot find name com` – prolink007 Jun 12 '17 at 20:12

0 Answers0