【发布时间】:2014-01-30 04:16:13
【问题描述】:
我想使用 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, Version=1.0.16.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。系统找不到指定的文件。
并在“credential =”行崩溃。我试图添加一些实际 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 错误页面中使用程序集加载跟踪,我尝试通过建议的配置文件进行挖掘,但没有任何效果。更一般地说,我尝试在 StackOverflow 中寻找这个问题,虽然我确实找到了一些提及,但这些材料都没有帮助。
【问题讨论】:
标签: asp.net .net google-api-dotnet-client