gpt4 book ai didi

c# - 如何在 Xamarin 中获取 GoogleApiClient 实例?

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:15 24 4
gpt4 key购买 nike

我想将我的 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;

关于c# - 如何在 Xamarin 中获取 GoogleApiClient 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37233100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com