2

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

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Mohamad Mahmoud Darwish
  • 3,865
  • 9
  • 51
  • 76
  • i find a good solution for reading from google sheet. check the following link https://stackoverflow.com/questions/48432846/how-to-read-data-from-google-spreadsheet-in-xamarin-forms/52556347#52556347 – Mohamad Mahmoud Darwish Oct 24 '18 at 14:36

2 Answers2

2

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.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • do you have any other library that help me in xamarin.forms – Mohamad Mahmoud Darwish Feb 13 '18 at 10:16
  • 1
    As far as i know there is no other library for doing this. I suggest you could take a copy of the client library and fix that its an open source projects so it should be doable. or write your own (*this is what i did for .net 3.5 which also wasn't supported.*) sorry to be the bearer of bad news there isnt going to be an easy fix for this. – Linda Lawton - DaImTo Feb 13 '18 at 10:20
0

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.

chuese
  • 11
  • 2
  • Actually Google APIs Client Library for working with Sheets v4. Supported Platforms: - .NET Framework 4.5+ - NetStandard1.3, providing .NET Core support. Legacy platforms: - .NET Framework 4.0 - Windows 8 Apps - Windows Phone 8.1 - Windows Phone Silverlight 8.0 Incompatible platforms: - .NET Framework < 4.0 - Silverlight - UWP (will build, but is known not to work at runtime) – Mohamad Mahmoud Darwish Feb 14 '18 at 15:51
  • Yes but check the beta version nugget package I mentioned. The comments there are :Supported Platforms: - .NET Framework 4.5+ - NetStandard1.3, providing .NET Core support - UWP (Universal Windows Platform) – chuese Feb 17 '18 at 09:06