Auth.GOOGLE_SIGN_IN_API cannot be used with Games.API

半城伤御伤魂 提交于 2019-12-06 16:30:59

Resolved by my self.
No need to add Auth.GOOGLE_SIGN_IN_API for getting User Profile Information if you already connected Games.API.


Connect:

googleApiClient = new GoogleApiClient.Builder(activity)
                .addConnectionCallbacks(connectionCallbacks)
                .addOnConnectionFailedListener(onConnectionFailedListener)
                .addApi(Games.API).addScope(Games.SCOPE_GAMES)
                .build();

If failed:

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(this, REQUEST_RESOLVE_ERR);
        } catch (IntentSender.SendIntentException e) {
            googleApiClient.connect();
            e.printStackTrace();
        }
    }
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case REQUEST_RESOLVE_ERR:
            if (resultCode == RESULT_OK) {
                if (!googleApiClient.isConnecting()
                            && !googleApiClient.isConnected())
                    googleApiClient.connect();
            }
            break;
    }
}

If connected:
Get User Profile Information:

String name = Games.Players.getCurrentPlayer(googleApiClient).getDisplayName();
Uri photo = Games.Players.getCurrentPlayer(googleApiClient).getIconImageUri();
//and more...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!