OAuth token with Google Play Game Services

匆匆过客 提交于 2019-12-06 12:10:28

问题


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.


回答1:


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();
        }
    }

    ...
}


来源:https://stackoverflow.com/questions/17730365/oauth-token-with-google-play-game-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!