3

I require to query data using Google BigQuery API, calling with service account.

However I am struggling to find .NET Samples, and there was no documentation included with the binary (Google.Apis.Bigquery.dll). Can anybody provide me with sample usage for C#.NET?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
user3508580
  • 171
  • 1
  • 10
  • possible duplicate of [Google BigQuery with .NET documentation/ samples](http://stackoverflow.com/questions/12443878/google-bigquery-with-net-documentation-samples) – Eluvatar Apr 10 '14 at 20:03
  • Hi Sir, This is an outdataed example and outdated namespaces, and even I am looking for an example with service account along with the Latest NUGET pacakge namespaces information. – user3508580 Apr 10 '14 at 20:42

1 Answers1

3

This information is coming from: Google APIs Client Library for .NET

That example shows how to use a service account with the Google+ api. I edited it a little for use with BigQuery.

using System;
using Google.Apis.Auth.OAuth2;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Bigquery.v2;
using Google.Apis.Services;

//Install-Package Google.Apis.Bigquery.v2
namespace GoogleBigQueryServiceAccount
{
class Program
{
    private static String ACTIVITY_ID = "z12gtjhq3qn2xxl2o224exwiqruvtda0i";
    static void Main(string[] args)
    {

        Console.WriteLine("BigQuery API - Service Account");
        Console.WriteLine("==========================");

        String serviceAccountEmail = "SERVICE_ACCOUNT_EMAIL_HERE";

        var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer(serviceAccountEmail)
           {
               Scopes = new[] { BigqueryService.Scope.DevstorageReadOnly }
           }.FromCertificate(certificate));

        // Create the service.
        var service = new BigqueryService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "BigQuery API Sample",
        });

        //Note: all your requests will run against Service.

    }
}

}

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449