Mohamad Mahmoud Darwish
Mohamad Mahmoud Darwish

Reputation: 4175

get Google Credential throws Unhandled Exception

On My Xamarin.forms Portable Project, I am trying to read information from google sheet:

using (var stream = this.Assets.Open(@"clientsecret.json"))
            {
                var secrets = GoogleClientSecrets.Load(stream).Secrets;
               //I get the secrets correctly     
     credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            secrets,
            Scopes,
            "user",
            CancellationToken.None,
            new FileDataStore(credPath,true)).Result;
}

I get

Unhandled Exception

System.AggregateException: One or more errors occurred.

when the complier trying to get credential, keep in your mind the same code is working fine in windows forms application

Upvotes: 2

Views: 494

Answers (2)

chuese
chuese

Reputation: 11

Sounds like it could be a similar issue I am/was facing with auth2 in a UWP app. I use the same kind of auth flow as per your code, and it throws an exception at runtime when I use the mainstream Google APIs .Net Client library. In my case, I was able to use the beta version of the library v1.31.0 beta 01, and that got my UWP app and the auth flow working fine. From looking at the branch the magic is that the beta libraries will default the FileDataStore to a PasswordVaultDataStore object for UWP, which seems to work fine. There are also other differences like UWP code receiver classes etc but I haven't really checked in detail. For all it's worth, try the beta library and see if it helps in your case.

Upvotes: 0

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116918

You appear to be using the Google APIs .Net client library. At this time the client library does not officially support Xamarin

Please see the issue here Investigate Xamarin support #984 or this one #840

Option 1:

Create a fork of the Google APIs .Net client library and fix any issues you can find. The client library is open source so this should be doable. I am sure we would be happy to accept a pull request if you get it working.

Option 2:

Create your own library for accessing just the sheets api. This may be the faster way to go but you need to have some understanding of how Google oauth works in order to do this.

Upvotes: 2

Related Questions