I am using "Google.Apis.Bigquery.v2 Client Library" with C#.
I am authorizing to Google BigQuery using "Service Account" (see http://www.afterlogic.com/mailbee-net/docs/OAuth2GoogleServiceAccounts.html). To create the X509 certificate I use the p12 key from the Google Developers Console. However, right now the json key is the default. Can I use it instead the p12 key?
I have the following code:
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();