C# で「Google.Apis.Bigquery.v2 クライアント ライブラリ」を使用しています。
「サービス アカウント」を使用して Google BigQuery を承認しています ( http://www.afterlogic.com/mailbee-net/docs/OAuth2GoogleServiceAccounts.htmlを参照)。X509 証明書を作成するには、Google Developers Console の p12 キーを使用します。ただし、現在は json キーがデフォルトです。p12 キーの代わりに使用できますか?
次のコードがあります。
string serviceAccountEmail = "xxxx@developer.gserviceaccount.com";
X509Certificate2 certificate;
using (Stream stream = new FileStream(@"C:\key.p12", FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (MemoryStream ms = new MemoryStream())
{
stream.CopyTo(ms);
certificate = new X509Certificate2(ms.ToArray(), "notasecret", X509KeyStorageFlags.Exportable);
}
}
// Create credentials
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] {
BigqueryService.Scope.Bigquery,
BigqueryService.Scope.CloudPlatform,
},
}.FromCertificate(certificate));
// Create the service
BaseClientService.Initializer initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My Application",
GZipEnabled = true,
};
BigqueryService service = new BigqueryService(initializer);
var projects = service.Projects.List().Execute();