Can't access Google Drive. Result Code = Canceled after StartResolutionForResult screen.

SenkhSenkh BRMember

Hello, I am new to Xamarin, and currently am building an App that needs to connect to Google Drive. To do this, I am following this tutorial.

Well, no matter what I do, after selecting an Account on the StartResolutionForResult screen, I receive a Canceled result on the OnActivityResult callback.

My first guess is that this is a problem on the Google Console Credentials, but comparing to other tutorials and to the one I am following, everything seems fine. My second guess is a StartResolutionForResult screen problem.

OK, here is the code.

First I check the service, this succeeds:

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if(GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this) == ConnectionResult.Success)
            {
                buildGoogleApiClient();
            }
        }

Build the Client:

private void buildGoogleApiClient()
{
      if (_googleApiClient == null)
      {
       _googleApiClient = new GoogleApiClient.Builder(this)
       .AddApi(DriveClass.API)
       .AddScope(DriveClass.ScopeFile)
       .AddConnectionCallbacks(this)
       .AddOnConnectionFailedListener(onConnectionFailed)
       .Build();
      }
}

Connects:

    protected override void OnStart()
    {
        base.OnStart();
        _googleApiClient.Connect();
    }

Receives the choose Account error:

    protected void onConnectionFailed(ConnectionResult result)
    {
        Log.Info(TAG, "GoogleApiClient connection failed: " + result);
      if (result.HasResolution)
      {
  try
        {
            result.StartResolutionForResult(this, REQUEST_CODE_RESOLUTION);
        }
        catch (IntentSender.SendIntentException e)
        {
            Log.Error(TAG, "Exception while starting resolution activity", e);
        }
     }

And finally receive the Canceled result code:

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_RESOLUTION)
        {
            switch (resultCode)
            {
                case Result.Ok:
                    _googleApiClient.Connect();
                    break;
                case Result.Canceled:
                    //Log.Error(TAG, "");
                    break;
                default:
                    Log.Error(TAG, "Should never be here: " + resultCode);
                    return;
            }
        }
    } 

Thank you very much for the help and patience, this is driving me nuts.

Answers

  • kunalsympackunalsympac Member ✭✭

    Hi Senkh, did you manage to solve this issue? I've come across the same problem and it's also driving me mad.

Sign In or Register to comment.