1

I am trying to gain access to my BigQuery enabled Google API project using the .net Google APIs.

Using a console application, I am trying to authenicate first by supplying my simple API key in the URI, then just trying to get the list of projects.

The error I am receiving when I call Fetch() on the project list is: Login Required [401]

var bigqueryService = new BigqueryService{ Key = "MY-API_KEY" };
var projectList = bigqueryService.Projects.List().Fetch();

I am purposefully not using OAuth2 as we don't need any user data.

Nick
  • 6,366
  • 5
  • 43
  • 62

2 Answers2

2

The API key simply identifies your app to the API console for quota purposes and other housekeeping. It's not authoritative for accessing BigQuery, as we do consider the BigQuery data as "user data."

If you're just trying to get an OAuth 2 access token for playing around quickly, you can use the OAuth 2 playground: https://code.google.com/oauthplayground/

This token will be valid for one hour and can be copied/pasted as the access_token query parameter

Here's the scope for BigQuery to use in the playground: https://www.googleapis.com/auth/bigquery

In the end, you'll either want to use the native client (out of band) flow: https://developers.google.com/accounts/docs/OAuth2InstalledApp

Or the server-to-server (service accounts) flow: https://developers.google.com/accounts/docs/OAuth2ServiceAccount

I don't have quick samples handy for those in .NET, but post another question on SO if you can't find them-- I'm sure someone will chip in!

Ryan Boyd
  • 2,978
  • 1
  • 21
  • 19
  • Thanks - we've moved onto the server-to-server approach using OAuth2 with help from [this question](http://stackoverflow.com/questions/10055158/is-there-a-json-web-token-jwt-example-in-c). However, all we get back when we POST to https://accounts.google.com/o/oauth2/token is a 400 - Bad Request response. Furthermore, are you sure that BQ actually supports service account access, as its not specified [here](https://code.google.com/p/google-api-php-client/wiki/OAuth2#Service_Accounts) – Nick Aug 10 '12 at 14:35
  • Yep - we have successfully used service accounts with BigQuery. Working on getting an accurate central page listing these APis. What's the body of the 400 response? Note: we hope to have support for service accounts in the .NET library directly soon (it's in code review now). – Ryan Boyd Aug 10 '12 at 18:24
  • Ok, good news re Service Accounts in the .net lib. Will the sample make use of a [JWT package like this](https://github.com/johnsheehan/jwt) or be all boiler plate? I ask because the amended example of the package in the link I sent applies R256 hashing by using a HMACSHA256 algorithm. Is this correct? – Nick Aug 12 '12 at 12:21
  • I've made only a small amount of progress so I've continued with [another question](http://stackoverflow.com/questions/11939026/google-oauth2-service-account-access-token-request-gives-invalid-request-respo), which includes the body of the 400 response. – Nick Aug 13 '12 at 17:12
0

You won't be able to use a simple API key - all authorization to the BigQuery API must happen via user interaction, or alternatively through a service account.

Michael Manoochehri
  • 7,931
  • 6
  • 33
  • 47
  • Thanks Michael, I've since started using the service account auth mechanism but have hit another wall... http://stackoverflow.com/questions/11939026/google-oauth2-service-account-access-token-request-gives-invalid-request-respo – Nick Aug 13 '12 at 17:14