Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set scope Google sign in on Android

I use Google API for signin on Android app.

Code here:

SignInButton btnLogin = (SignInButton) findViewById(R.id.sign_in_button);

btnLogin.setOnClickListener(this);

Scope[] scopes = new Scope[2];
scopes[0] = new Scope("https://www.googleapis.com/auth/admin.directory.user.readonly");
scopes[1] = new Scope("https://www.googleapis.com/auth/contacts.readonly");

btnLogin.setScopes(scopes);

Sign in success with access token, but the access token only default scopes:

"userinfo.profile" & "userinfo.email" & "auth/plus.me"

Can you help me to get 2 scopes:

"/auth/admin.directory.user.readonly" & "/auth/contacts.readonly"
like image 302
Nguyen Lam Phuoc Avatar asked Jan 09 '16 06:01

Nguyen Lam Phuoc


2 Answers

You can refer to the following syntax:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PLUS_LOGIN)) // "https://www.googleapis.com/auth/plus.login"
                .requestScopes(new Scope(Scopes.PLUS_ME)) // "https://www.googleapis.com/auth/plus.me"
                .requestEmail()
                .build();

More details at this documentation. Hope it helps!

like image 176
BNK Avatar answered Oct 01 '22 05:10

BNK


You can add multiple Scopes in requestScopes().

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PLUS_LOGIN), new Scope(Scopes.PLUS_ME))
                .requestEmail()
                .build();
like image 39
solamour Avatar answered Oct 01 '22 04:10

solamour