gpt4 book ai didi

c# - 带有 C# 示例的 Google BigQuery

转载 作者:行者123 更新时间:2023-11-30 16:12:24 30 4
gpt4 key购买 nike

我需要使用 Google BigQuery API 查询数据,使用服务帐户调用。

但是我正在努力寻找 .NET 示例,并且二进制文件 (Google.Apis.Bigquery.dll) 中没有包含任何文档。任何人都可以向我提供 C#.NET 的示例用法吗?

最佳答案

此信息来自:Google APIs Client Library for .NET

该示例展示了如何将服务帐户与 Google+ api 一起使用。我对其进行了一些编辑以用于 BigQuery。

using System;
using Google.Apis.Auth.OAuth2;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Bigquery.v2;
using Google.Apis.Services;

//Install-Package Google.Apis.Bigquery.v2
namespace GoogleBigQueryServiceAccount
{
class Program
{
private static String ACTIVITY_ID = "z12gtjhq3qn2xxl2o224exwiqruvtda0i";
static void Main(string[] args)
{

Console.WriteLine("BigQuery API - Service Account");
Console.WriteLine("==========================");

String serviceAccountEmail = "SERVICE_ACCOUNT_EMAIL_HERE";

var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);

ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { BigqueryService.Scope.DevstorageReadOnly }
}.FromCertificate(certificate));

// Create the service.
var service = new BigqueryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "BigQuery API Sample",
});

//Note: all your requests will run against Service.

}
}

关于c# - 带有 C# 示例的 Google BigQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22997500/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com