How to get a Google API client instance in xamarin?

I want to integrate my xamarin Android application with Google play service rankings and achievements. I don't know how to convert the following 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 the following

GoogleApiClient api = new GoogleApiClient.Builder(this)
           .AddApi(Android.Gms.Games.API)
           .Build();

Display errors under "Android. GMS. Games. API"

All operations mentioned in this stack overflow thread are invalid. It seems that most of them have been discarded

Please indicate whether there are other easy ways to integrate with leaderboards

Edit: changes have been made and the following error is now given

resolvent:

You will be able to access the Google client API in the following ways:

var googleClientAPI = new GoogleApiClient.Builder(Application.Context).AddApi(XXX).Build();

Use blocked connections as an example of a quick test:

var client = new GoogleApiClient.Builder(Application.Context)
                                .AddApi(GamesClass.API)
                                .AddScope(GamesClass.ScopeGames)
                                .Build();
Task.Run(() => {
    client.BlockingConnect();
    System.Diagnostics.Debug.WriteLine(client.IsConnected);
});

Note: if you have registered the application, otherwise a fatal developer error will occur... See play connecting

Because you need access to leaderboards and achievements, make sure you have added the following packages:

> Xamarin.GooglePlayServices.Games > Xamarin.GooglePlayServices.Identity

These will automatically include. Base and. Basement packages

>Namespace to view after adding a package:

using Android.Gms.Common.Apis;
using Android.Gms.Games.LeaderBoard;
using Android.Gms.Games.Achievement;

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>