maclir
maclir

Reputation: 3309

OAuth token with Google Play Game Services

Is there a way to get the token that was used to log in the user with Google Play Game Services?

I'm looking for something like:

@Override
public void onSignInSucceeded() {
    String email = getGamesClient().getCurrentAccountName();
    String token = getGamesClient().getToken();
}

I need this to authenticate the user when they are contacting my own server.

Upvotes: 1

Views: 1913

Answers (1)

maclir
maclir

Reputation: 3309

This is how I managed to get the token:

@Override
public void onSignInSucceeded() {
    String email = getGamesClient().getCurrentAccountName();
    String scopes = getScopes();
    new registerBackground(getApplicationContext()).execute(email, scopes);
}


private class registerBackground extends AsyncTask<String, Void, Void> {
    Context context;
    registerBackground (Context context) {
        this.context = context;
    }

    @Override
    protected Void doInBackground(String... params) {
        try {
            String oAuthToken = GoogleAuthUtil.getToken(context, params[0], params[1]);
            ...
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    ...
}

Upvotes: 1

Related Questions