Reputation: 551
I want to integrate my xamarin android app with google play services leaderboards and achievements. I am not getting how to convert below code from android documentation to c#.
// Create the Google Api Client with access to the Play Game and Drive services.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER) // Drive API
.build();
// ...
I tried to convert something like below
GoogleApiClient api = new GoogleApiClient.Builder(this)
.AddApi(Android.Gms.Games.API)
.Build();
It's giving error under "Android.Gms.Games.API"
None of the things mentioned in this stack overflow thread are working. Looks like most of these things deprecated.
Please suggest if any other easy way available to integrate with leaderboards.
EDIT: Made changes and now giving below error.
Upvotes: 3
Views: 2180
Reputation: 74184
You will be able to get access to GoogleClientAPI
via:
var googleClientAPI = new GoogleApiClient.Builder(Application.Context).AddApi(XXX).Build();
var client = new GoogleApiClient.Builder(Application.Context)
.AddApi(GamesClass.API)
.AddScope(GamesClass.ScopeGames)
.Build();
Task.Run(() => {
client.BlockingConnect();
System.Diagnostics.Debug.WriteLine(client.IsConnected);
});
Since you are needing access to leaderboard and achievements, make sure that you have added the packages:
Xamarin.GooglePlayServices.Games
Xamarin.GooglePlayServices.Identity
These will auto-include the .Base
and .Basement
package
using Android.Gms.Common.Apis;
using Android.Gms.Games.LeaderBoard;
using Android.Gms.Games.Achievement;
Upvotes: 3