【问题标题】:OAuth token with Google Play Game Services带有 Google Play 游戏服务的 OAuth 令牌
【发布时间】:2013-07-17 19:27:49
【问题描述】:

有没有办法获取用于使用 Google Play 游戏服务登录用户的令牌?

我正在寻找类似的东西:

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

当用户联系我自己的服务器时,我需要它来验证用户身份。

【问题讨论】:

    标签: android google-play-games


    【解决方案1】:

    这就是我设法获得令牌的方式:

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

    【讨论】:

    • 感谢分享,完美运行。您是否实现了最新版本,正如 Google 所说的 GoogleAuthUtil.getToken(...) 方法现在不安全 :-( 我不需要访问 Google API 的服务器端,只是为了验证令牌,所以也许它是安全的目的?
    • @poirot 还没有花时间。如果您对新方法有任何成功,请在此处更新。 :)
    • 在这里查看我自己对自己问题的回答 (stackoverflow.com/questions/40069681/…) 我终于找到了解决方案!我花了几天时间才弄清楚:-D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 2013-05-19
    • 2021-05-09
    • 1970-01-01
    • 2013-07-31
    • 2017-09-27
    相关资源
    最近更新 更多