Google API客户端OAuth始终返回已取消

the*_*ean 6 android google-api xamarin.android xamarin google-fit

我正在尝试使用Google Fit History API,我遇到了一个问题,在我使用ConnectionResult.StartResolutionForResult提示用户使用他们的Google帐户之后,我总是会收到取消代码CANCELED,即使用户通过对话.据我所知,我已经按照此处的指南(https://developers.google.com/fit/android/get-api-key)查看了这封信.我在Developers控制台中有一个项目.我在控制台中启用了Fitness API.我在开发机器上使用调试密钥库生成了一个客户端ID.以下是开发者控制台的一些截图: 在开发者控制台中启用API的屏幕截图 开发人员控制台中OAuth客户端ID的屏幕截图

我正在使用Xamarin.Android进行编程,并按照此处的示例进行操作.(请注意,我确实安装了Xamarin.GooglePlayServices.Fitness包):https: //github.com/xamarin/monodroid-samples/tree/master/google-services/Fitness/BasicHistoryApi

以下是代码的关键区域:

    mClient = new GoogleApiClient.Builder (this)
        .AddApi (FitnessClass.HISTORY_API)
        .AddScope (new Scope (Scopes.FitnessActivityReadWrite))
        .AddConnectionCallbacks (clientConnectionCallback)
        .AddOnConnectionFailedListener (result => {
            Log.Info (TAG, "Connection failed. Cause: " + result);
            if (!result.HasResolution) {
                // Show the localized error dialog
                GooglePlayServicesUtil.GetErrorDialog (result.ErrorCode, this, 0).Show ();
                return;
            }
            // The failure has a resolution. Resolve it.
            // Called typically when the app is not yet authorized, and an
            // authorization dialog is displayed to the user.
            if (!authInProgress) {
                try {
                    Log.Info (TAG, "Attempting to resolve failed connection");
                    authInProgress = true;
                    result.StartResolutionForResult (this, REQUEST_OAUTH);
                } catch (IntentSender.SendIntentException e) {
                    Log.Error (TAG, "Exception while starting resolution activity", e);
                }
            }
        }).Build ();
Run Code Online (Sandbox Code Playgroud)

...

    protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
    {
        if (requestCode == REQUEST_OAUTH) {
            authInProgress = false;
            if (resultCode == Result.Ok) {
                // Make sure the app is not already connected or attempting to connect
                if (!mClient.IsConnecting && !mClient.IsConnected) {
                    mClient.Connect ();
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

使用statusCode = SIGN_IN_REQUIRED调用OnFailedConnectionListener,然后调用StartResolutionForResult并弹出对话框以供用户选择他们的Google帐户.一旦显示对话框,我在LogCat中收到以下错误.请注意,这是在他们选择帐户之前.

02-26 15:56:36.459: E/MDM(17800): [63567] b.run: Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
Run Code Online (Sandbox Code Playgroud)

一旦用户选择了帐户,OnActivityResult就会被调用,而resultCode总是被"取消",这应该表示用户已经解除了对话框,但这肯定不是这里发生的事情.有帮助吗?它在开发者控制台中闻起来有些不对劲,但经过100次导航后,结果相同,我开始变得疯狂.

the*_*ean 3

所以我的问题是我使用了错误的 debug.keystore。我的 Mac 同时安装了 Android Studio 和 Xamarin Studio。我错误地认为 Xamarin 使用的是“~/.android/debug.keystore”,但事实证明他们将其放入“~/.local/share/Xamarin/Mono for Android/debug.keystore”中,更改为使用 SHA1从这个键解决了我的问题。有关 Xamarin 密钥的信息: https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/MD5_SHA1/#OSX