0

Starting working on Android app in java, and have no clue how to iterate things correctly.

I have Google sign in object:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestServerAuthCode(this.getString(R.string.auth_client_id))
                .requestScopes(scopes)
                .requestEmail()
                .requestProfile()
                .build();

And array of scopes:

// split scope params
   String[] scopes = scope.split("\\+|_|__");

   List<String> list = new ArrayList<>();
   for (int i = 0; i < scopes.length; i++) {
       list.add(new Scope(scopes[i]));
   }

Ho to iterate ".requestScopes(scopes)" in Google sign in options object, because .requestScopes() is not allowing me to enter array value, only string is allowed.

Your help will help me to save additional half of the day probably.

1 Answer 1

1

You can use this method to add multiple scopes https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInOptions.Builder.html#requestScopes(com.google.android.gms.common.api.Scope,%20com.google.android.gms.common.api.Scope...), e.g.:

// split scope params
String[] scopeStrings = scope.split("\\+|_|__");

Scope firstScope = new Scope(scopeStrings[0]);
Scope[] scopes = new Scope[scopeStrings.length - 1];
for (int i = 1; i < scopeStrings.length; i++) {
    scopes[i - 1] = new Scope(scopeStrings[i]);
}

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestServerAuthCode(this.getString(R.string.auth_client_id))
            .requestScopes(firstScope, scopes)
            .requestEmail()
            .requestProfile()
            .build();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, Sergey! That was exactly what I needed ;)

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.