Я использую "Клиентскую библиотеку Google.Apis.Bigquery.v2" с С#.
Я разрешаю Google BigQuery использовать "Учетную запись службы" (см. http://www.afterlogic.com/mailbee-net/docs/OAuth2GoogleServiceAccounts.html). Чтобы создать сертификат X509, я использую ключ p12 из Google Developers Console. Тем не менее, сейчас json-ключ является значением по умолчанию. Могу ли я использовать его вместо ключа p12?
У меня есть следующий код:
string serviceAccountEmail = "[email protected]";
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();