3

While Creating Service Account for Google BigQuery, There are two key file type. 1. P12 Key File 2. JSON Key File.

I can able to connect Google BigQuery with Service Account Credentials using P12 Key File by using following code.

String serviceAccountEmail = "XXXX@developer.gserviceaccount.com";

            var certificate = new X509Certificate2(@"FileName.p12", "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));

            BigqueryService Service = new BigqueryService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "PROJECT NAME"
            });

Now i am trying to connect Service Account Credentials using JSON file type, but i could not get the proper syntax for creating.

How can we connect Google BigQuery with Service Account Credentials using JSON File?

Thanks,

selva kumar
  • 1,086
  • 2
  • 11
  • 30
  • This might help you. The answer in the link shows example of using JSON file to connect to bigquery. http://stackoverflow.com/questions/19977864/nativeapplicationclient-is-not-supported-any – Patel Jun 23 '15 at 17:48
  • @Patel Your suggested link shows Connecting Google Big query using Web application based JSON file but i am expecting Connecting through Service account based JSON file. – selva kumar Aug 18 '15 at 07:45
  • Possible duplicate of [Is it possible to use json key instead of p12 key for service account credentials?](http://stackoverflow.com/questions/31840686/is-it-possible-to-use-json-key-instead-of-p12-key-for-service-account-credential) – Andrey Belykh Sep 28 '16 at 15:36

2 Answers2

2

I got the link, Which indicates Service Account Authentication using JSON file in C# application is not yet added in Google BigQuery API, So i would like to close the question.

https://github.com/google/google-api-dotnet-client/issues/533

selva kumar
  • 1,086
  • 2
  • 11
  • 30
1

It is now possible (I used v 1.13.1.0 of Google APIs).

GoogleCredential credential;
using (Stream stream = new FileStream(@"C:\mykey.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
    credential = GoogleCredential.FromStream(stream);
}

string[] scopes = new string[] {
    BigqueryService.Scope.Bigquery,
    BigqueryService.Scope.CloudPlatform, 
};
credential = credential.CreateScoped(scopes);

BaseClientService.Initializer initializer = new BaseClientService.Initializer()
{
    HttpClientInitializer = (IConfigurableHttpClientInitializer)credential,
    ApplicationName = "My Application",
    GZipEnabled = true,
};
BigqueryService service = new BigqueryService(initializer);
Andrey Belykh
  • 2,578
  • 4
  • 32
  • 46