Google BigQuery 询问 Gmail 确认,在生产环境中处理的最佳方式
Google BigQuery asking Gmail Confirmation, Best way to handle in Production Environment
我创建了一个 C# 控制台应用程序来读取 BigQuery 数据。
虽然我是第一个 运行 这个控制台应用程序,它打开浏览器 window 请求 Google 接受,以后它不会在同一台机器上请求许可。
问题:它是第一次请求每台机器的权限,如果是,哪种是部署 BigQuery 应用程序的最佳方式,bz 客户端需要使用 Developer ID 接受 Gmail 访问?这是有道理的,或者哪种是在生产环境中处理 Google BigQuery 应用程序的最佳方式?
这是代码。
using Google.Apis.Auth.OAuth2;
using System.IO;
using System.Threading;
using Google.Apis.Bigquery.v2;
using Google.Apis.Bigquery.v2.Data;
using System.Data;
using Google.Apis.Services;
using System;
namespace GoogleBigQuery
{
public class Class1
{
private static void Main()
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open,
FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { BigqueryService.Scope.Bigquery },
"user", CancellationToken.None).Result;
}
// Create and initialize the Bigquery service. Use the Project Name value
// from the New Project window for the ApplicationName variable.
BigqueryService Service = new BigqueryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "PROJECT NAME"
});
string query = "YOUR QUERY";
JobsResource j = Service.Jobs;
QueryRequest qr = new QueryRequest();
qr.Query = query;
DataTable DT = new DataTable();
int i = 0;
QueryResponse response = j.Query(qr, "PROJECT ID").Execute();
if (response != null)
{
int colCount = response.Schema.Fields.Count;
foreach (var Column in response.Schema.Fields)
{
DT.Columns.Add(Column.Name);
}
foreach (TableRow row in response.Rows)
{
DataRow dr = DT.NewRow();
for (i = 0; i < colCount; i++)
{
dr[i] = row.F[i].V;
}
DT.Rows.Add(dr);
}
}
else
{
Console.WriteLine("Response is null");
}
}
}
}
谢谢,
塞尔瓦库玛 S
我不是 C# 专家,但我可以看到您正在使用 "GoogleWebAuthorizationBroker" - 这确实是一个帮助程序 class,它将打开网页以获取最终用户身份验证和授权。
改为使用 OAuth2ServiceAccount 进行机器对机器身份验证 (https://developers.google.com/identity/protocols/OAuth2ServiceAccount)。
有关示例 C# 代码,请参阅“where can i find ServiceAccountCredential”。
我创建了一个 C# 控制台应用程序来读取 BigQuery 数据。
虽然我是第一个 运行 这个控制台应用程序,它打开浏览器 window 请求 Google 接受,以后它不会在同一台机器上请求许可。
问题:它是第一次请求每台机器的权限,如果是,哪种是部署 BigQuery 应用程序的最佳方式,bz 客户端需要使用 Developer ID 接受 Gmail 访问?这是有道理的,或者哪种是在生产环境中处理 Google BigQuery 应用程序的最佳方式?
这是代码。
using Google.Apis.Auth.OAuth2;
using System.IO;
using System.Threading;
using Google.Apis.Bigquery.v2;
using Google.Apis.Bigquery.v2.Data;
using System.Data;
using Google.Apis.Services;
using System;
namespace GoogleBigQuery
{
public class Class1
{
private static void Main()
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open,
FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { BigqueryService.Scope.Bigquery },
"user", CancellationToken.None).Result;
}
// Create and initialize the Bigquery service. Use the Project Name value
// from the New Project window for the ApplicationName variable.
BigqueryService Service = new BigqueryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "PROJECT NAME"
});
string query = "YOUR QUERY";
JobsResource j = Service.Jobs;
QueryRequest qr = new QueryRequest();
qr.Query = query;
DataTable DT = new DataTable();
int i = 0;
QueryResponse response = j.Query(qr, "PROJECT ID").Execute();
if (response != null)
{
int colCount = response.Schema.Fields.Count;
foreach (var Column in response.Schema.Fields)
{
DT.Columns.Add(Column.Name);
}
foreach (TableRow row in response.Rows)
{
DataRow dr = DT.NewRow();
for (i = 0; i < colCount; i++)
{
dr[i] = row.F[i].V;
}
DT.Rows.Add(dr);
}
}
else
{
Console.WriteLine("Response is null");
}
}
}
}
谢谢, 塞尔瓦库玛 S
我不是 C# 专家,但我可以看到您正在使用 "GoogleWebAuthorizationBroker" - 这确实是一个帮助程序 class,它将打开网页以获取最终用户身份验证和授权。
改为使用 OAuth2ServiceAccount 进行机器对机器身份验证 (https://developers.google.com/identity/protocols/OAuth2ServiceAccount)。
有关示例 C# 代码,请参阅“where can i find ServiceAccountCredential”。