想使用OAuth2和.NET 4.5框架构建一个GoogleBigQueryC#ASP.NET应用程序
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
将相关的“usings”放在代码隐藏文件“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" } ); } } }
将这个特定的页面设置为项目开始页面
APIS & auth -> Credentials -> CREATE NEW CLIENT ID
确保正确地映射到客户端。使用Server.MapPath
<https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2>
DEBUG -> Start Debugging