以下のコードを使用して、プロジェクト、データ セット、およびテーブルのリストを取得できます。
Public-Data を取得するには、以下のコードを使用できます
var SampleTableList = Service.Tables.List("publicdata", "samples").Execute();
publicdata には DataSet (サンプル) が 1 つしかないため、新しいデータセットを追加することはできず、このコードは正しく機能します。
ServiceAccountEmail、KeyFile パス、Key Secret などのプロパティを変更します。
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;
using System.Security.Cryptography.X509Certificates;
namespace GoogleBigQuery
{
public class Class1
{
private static void Main()
{
try
{
String serviceAccountEmail = "SERVICE ACCOUNT EMAIL";
var certificate = new X509Certificate2(@"KEY FILE NAME & PATH", "KEY SECRET", X509KeyStorageFlags.Exportable);
// SYNTAX: var certificate=new X509Certificate2(KEY FILE PATH+NAME (Here it resides in Bin\Debug folder so only name is enough), SECRET KEY, X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { BigqueryService.Scope.Bigquery, BigqueryService.Scope.BigqueryInsertdata, BigqueryService.Scope.CloudPlatform, BigqueryService.Scope.DevstorageFullControl }
}.FromCertificate(certificate));
// 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 = "APPLICATION NAME"
});
var SampleTableList = Service.Tables.List("publicdata", "samples").Execute();
var projectList = Service.Projects.List().Execute();
foreach (var projectDet in projectList.Projects)
{
var DataSetList = Service.Datasets.List(projectDet.Id).Execute();
foreach (var DataSetDet in DataSetList.Datasets)
{
var TablesList = Service.Tables.List(projectDet.Id, DataSetDet.Id).Execute();
}
}
}
catch (Exception e)
{
Console.WriteLine("Error Occurred: " + e.Message);
}
Console.ReadLine();
}
}
}