我在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,
}; …Run Code Online (Sandbox Code Playgroud) c# google-bigquery google-api-dotnet-client google-sheets-api