其他分享
首页 > 其他分享> > 如何在Xamarin中获取GoogleApiClient实例?

如何在Xamarin中获取GoogleApiClient实例?

作者:互联网

我想将我的xamarin android应用程序与Google Play服务排行榜和成就集成在一起.我没有得到如何将下面的代码从android documentation转换为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();

    // ...

我试图转换如下内容

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

在“ Android.Gms.Games.API”下显示错误

this堆栈溢出线程中提到的所有操作均无效.似乎其中大多数东西已被弃用.

请提出是否有其他简便方法可与排行榜集成.

编辑:进行了更改,现在给出以下错误.

enter image description here

解决方法:

您将可以通过以下方式访问GoogleClientAPI:

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);
});

注意:前提是您已经注册了应用程序,否则将出现致命的开发人员错误…请参阅Play Connecting

由于您需要访问排行榜和成就,因此请确保已添加以下软件包:

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

这些将自动包括.Base和.Basement包

>在添加软件包后要查看的命名空间:

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

标签:xamarin,xamarin-android,c,android
来源: https://codeday.me/bug/20191118/2029832.html