获取Google Credential会抛出未处理的异常 [英] get Google Credential throws Unhandled Exception

查看:350
本文介绍了获取Google Credential会抛出未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Xamarin.forms 可移植项目中,我试图从 google表

 使用(var stream = this.Assets.Open(@clientsecret.json ))
{
var secrets = GoogleClientSecrets.Load(stream).Secrets;
//我正确得到秘密
凭证= GoogleWebAuthorizationBroker.AuthorizeAsync(
秘密,
作用域,
用户,
CancellationToken.None,
新的FileDataStore(credPath,true))。
}

我得到


未处理的异常



System.AggregateException:发生一个或多个错误。

当编译器试图获得凭证时,请记住相同的代码在Windows窗体应用程序中正常工作。

解决方案您似乎正在使用 Google API .Net客户端库。此时客户端库不会正式支持Xamarin



请在此处查看问题调查Xamarin支持#984 或这一个#840



选项1:

创建 Google APIs .Net客户端库的分支并修复您遇到的任何问题可以找到。客户端库是开源的,所以这应该是可行的。我相信,如果你能得到它,我们会很乐意接受拉请求。



选项2:

创建您自己的库来访问表单api。这可能是更快的方法,但您需要对Google oauth的工作原理有所了解。


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

解决方案

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.

这篇关于获取Google Credential会抛出未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆