我想使用OAuth2和.Net 4.5框架构建Google BigQuery C#ASP.net应用程序。我运行了这些NuGet安装
Install-Package Google.Apis.Bigquery.v2 -Pre
Install-Package Google.Apis.Authentication.OAuth2 -Version 1.2.4696.27634
Install-Package Google.Apis -Pre
Install-Package Google.Apis.Auth -Pre
然后将相关的“用法”放在代码隐藏文件“ default.aspx.cs”中:
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Bigquery.v2;
using Google.Apis.Bigquery.v2.Data;
namespace BigQueryDemoApp
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
UserCredential credential;
FileStream stream;
using (stream = new FileStream(
Server.MapPath("~/client_secrets.json"),
FileMode.Open, FileAccess.Read)
)
{
GoogleWebAuthorizationBroker.Folder =
"Tasks.Auth.Store";
credential = GoogleWebAuthorizationBroker.
AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { BigqueryService.Scope.Bigquery },
"user", CancellationToken.None).Result;
}
// Initialize the service.
var Service = new BigqueryService(
new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "BigQueryDemo"
}
);
}
}
}
我将此特定页面设置为项目开始页面。我在Google控制台上构建客户端ID文件时选择了“已安装的应用程序”
APIS & auth -> Credentials -> CREATE NEW CLIENT ID
并且确保在VS2013中使用解决方案资源管理器添加了此文件(client_secrets.json)。在后面的代码中,我确保使用Server.MapPath正确映射到client_secrets文件。对于凭证机制,我使用了以下代码
<https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2>
作为起点。当我运行该应用程序时,它返回一个浏览器错误页面,该页面以
无法加载文件或程序集“ Microsoft.Threading.Tasks.Extensions.Desktop,版本= 1.0.16.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a”或其依赖项之一。该系统找不到指定的文件。
并在“凭据=”行崩溃。我试图添加一些实际的ASP.net崩溃的浏览器页面的图像,其中显示了程序集加载跟踪/堆栈跟踪/等,但看来我没有此帐户的权限。当我在“ credential =”行设置断点,然后通过
DEBUG -> Start Debugging
在VS2013中,页面在“ credential =“行停止,并打开文件选择器,查找文件
"GoogleClientSecrets.cs"
从目录
“ c:\ code \ google.com \ google-api-dotnet-client \ default \ Tools \ Google.Apis.Release \ bin \ Debug \ output \ default \ Src \ GoogleApis.Auth \ OAuth2 \ GoogleClientSecrets.cs”
在驱动器上没有位置。使用生成的ASP.net错误页面中的Assembly Load Trace,我尝试浏览建议的配置文件,但是没有任何效果。更一般而言,我尝试在StackOverflow中寻找此问题,尽管确实找到了一些提及,但这些材料都无济于事。
因为该错误是基于Microsoft.Bcl.Async的最新版本在.NET 4.5中不起作用的事实,所以您可以尝试执行以下操作:
打开软件包管理器控制台,然后运行以下命令:
1)卸载Microsoft.Bcl.Async -Force包
2)安装Microsoft.Bcl.Async -Package 1.0.16版
它适用于我当前正在编写的示例。请让我知道它是否适合您。
UPDATE(3月21日):您可以更新包(新版本1.0.166-β可- https://www.nuget.org/packages/Microsoft.Bcl.Async/1.0.166-beta)。
我在带有.NET 4.5框架的VS2013上对其进行了测试,并且可以正常工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句