Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Play Game Services client setup and connecting

I've been working on game using the LibGDX framework and now I would like to set it up with the google play services to use leaderboards and set some achievements etc.

First question:

To use the GamesClient library is it necessary to request a token or some kind of login to google?

Second question:

I've created my client ID using the debug key, so I could easily test the game through eclipse. But I'm always refused to connect (GamesClient.connect()). I build the GamesClient through its Builder:

GamesClient.Builder gcb = new GamesClient.Builder(adView.getContext(), this, this);
                    gcb.setAccountName(accounts[0].name);
                    gcb.setViewForPopups(adView);
GamesClient gc = gcb.create();

Later when its time to call gc.connect(), it just calls the overriden onConnectionFailed();

I've added the meta-data to my android manifest, like this:

   <application
   ....
   <meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
   ....

The app_id content is the 12 digit or so from the client ID i've created for the game.(i've also tried with the full ID).

So I think thats not the problem.

More information: Client ID screenshot

Thanks in advance for your help!

like image 679
couceirof Avatar asked Jan 30 '26 05:01

couceirof


1 Answers

All set! Finally after some tries without result, here is the method (suitable for libgdx users).

Answer to the First Question: There's no need at all to get requests or even use the AuthUtil class provided by google.

Answer to the Second Question:

Make sure to read some tutorials about GamesClient and its implementation.

Step1: Get the BaseGameUtils library provided by Google, here.

Step2: implement GameHelper.GameHelperListenner on your MainActivity, for example:

public class MainActivity extends AndroidApplication implements GameHelper.GameHelperListener

and declare a GameHelper that will do all the sign in work for you. (dont forget to call its constructor and setup method, see GameHelper class for more information).

Step3: call beginUserInitiatedSignIn() (from the GameHelper instance) to start the sign in flow.

Thats it!

Advice: Follow the Type-a-number game tutorial to understand the flow of sign in (instructions in the readme file) here.

like image 194
couceirof Avatar answered Jan 31 '26 21:01

couceirof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!