get Google Credential throws Unhandled Exception

前提是你 提交于 2020-01-02 16:18:06

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/48763914/get-google-credential-throws-unhandled-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!