Home > Uncategorized > Google #BigQuery GoogleCredential json file based authentication

Google #BigQuery GoogleCredential json file based authentication


Google’s big query is a very cost effective means of storing structured data, and it has c# support. Following the quick start example, I didn’t like the way it required the use of the GOOGLE_APPLICATION_CREDENTIALS environment variable to connect to the service. That would be a deployment headache.

So, after downloading the JSON credentials file, which looked like this:

“type”: “service_account”,
“project_id”: “xxxxx”,
“private_key_id”: “xxxx”,
“private_key”: “—–BEGIN PRIVATE KEY—– xxx —–END PRIVATE KEY—–\n”,
“client_email”: “xxxxx.gserviceaccount.com”,
“client_id”: “xxxxxxx”,
“auth_uri”: “https://accounts.google.com/o/oauth2/auth”,
“token_uri”: “https://accounts.google.com/o/oauth2/token”,
“auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs”,
“client_x509_cert_url”: “https://www.googleapis.com/robot/v1/metadata/x509/xxxxxx%40developer.gserviceaccount.com”

I then modified the code in CreateAuthorizedClient as follows:

var fs = new FileStream(@”C:\..your-credentials.json”,FileMode.Open);
GoogleCredential credential = GoogleCredential.FromStream(fs);

Which worked a charm. I then had to import my own data into bigQuery, and see if I could query it, and that worked fine too – although I had to enable billing on the account *and project* before I could add my own data.


Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: