MrStahlfelge / gdx-gamesvcs

Easy integration of gameservices in your libGDX game: Google Play Games, Apple Game Center, Amazon GameCircle and more
Apache License 2.0
113 stars 20 forks source link

ERROR while show leaderboards #50

Closed hdls19 closed 2 years ago

hdls19 commented 2 years ago

Hi

First, thanks for the your work

I'm using your library in my game and getting an error when I call the gsClient.showLeaderboards() method

image

The code i am using in AndroidLauncher:

public class AndroidLauncher extends AndroidApplication {

    private GpgsClient gpgsClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AsteroidBustersXGame game = new AsteroidBustersXGame();

        this.gpgsClient = new GpgsClient()
                .setGpgsLeaderboardIdMapper(new IGameServiceIdMapper<String>() {

                    @Override
                    public String mapToGsId(String independantId) {
                        return GpgsMappers.mapToGpgsLeaderboard(independantId);
                    }
                })
                .initialize(this, false);
        game.gsClient = gpgsClient;

        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        config.useAccelerometer = false;
        config.useCompass = false;
        config.useImmersiveMode = true;
        initialize(game, config);
    }
}

Main Game Class create() method:

if (gsClient == null) {
    Gdx.app.log("GS_CLIENT", "GsClient is null");
    gsClient = new MockGameServiceClient(1) {
        @Override
        protected Array<ILeaderBoardEntry> getLeaderboardEntries() {
            return null;
        }

        @Override
        protected Array<String> getGameStates() {
            return null;
        }

        @Override
        protected byte[] getGameState() {
            return new byte[0];
        }

        @Override
        protected Array<IAchievement> getAchievements() {
            return null;
        }

        @Override
        protected String getPlayerName() {
            return null;
        }
    };
}

Gdx.app.log("GS_CLIENT", "GsClient set listener");
gsClient.setListener(this);

//My game initialization

Gdx.app.log("GS_CLIENT", "GsClient resume session");
gsClient.resumeSession();

Where I call showLeaderboards() method:

highscoresButton = new ImageButton(highscoresStyle);
highscoresButton.addListener(new ClickListener() {

    @Override
    public void clicked(InputEvent event, float x, float y) {
        try {
            game.gsClient.showLeaderboards(LEADERBOARD1);
        }
        catch (GameServiceException e) {
            Gdx.app.error("GS_CLIENT", "Failed to show leaderboards", e);
        }
    }
});

GpgsMappers class:

public class GpgsMappers {

    public static String mapToGpgsLeaderboard(String leaderboardId) {
        String gpgsId = null;

        if (leaderboardId != null) {
            if (leaderboardId.equals(AsteroidBustersXGame.LEADERBOARD1))
                gpgsId = "CgkIjOjVy8gdEAIQAQ";
        }

        return gpgsId;
    }
}

I also have a version of gdx 1.10.0, in the example its - 1.9.8. Most likely the problem is somewhere else.

Authorization passes - a welcome gpgs popup window appears with my username, but when click 'Highscores' it's load gpgs highscores page, but loading is freezing

Thanks in advance

hdls19 commented 2 years ago

I also get error when call fetchLeaderboardEntries() method: image

MrStahlfelge commented 2 years ago

You will get this error on every call. You need to do what the error tells you: link your app in the Play Games dev console.

hdls19 commented 2 years ago

I have already registered metadata app_id in AndroidManifest.xml image

which matches with OAuth 2.0 Client IDs on Google Cloud Platform image

Please tell me what else should I do?

MrStahlfelge commented 2 years ago

Google Play Games is different to set up. https://developers.google.com/games/services/console/enabling

hdls19 commented 2 years ago

I found out what the reason was - in my console in Play Games Services > Setup and Management > Configuration was only 1 credentials for release. When add debug credentials - then everything worked