微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐