Database Reference
In-Depth Information
Let's add the project ID, our new client ID, and the BigQuery scope as variables in
our application. Listing 6.2 demonstrates how to define an authorization f low, using
the Google API Client Library for JavaScript.
Listing 6.2 Adding the project id, client id, and scope information
<html>
<head>
<script src="https://apis.google.com/js/client.js"></script>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script>
// Your project ID and client ID
var project_id = 'XXXXX123456';
var client_id = 'XXXXX123456.apps.googleusercontent.com';
var config = {
'client_id': client_id,
'scope': 'https://www.googleapis.com/auth/bigquery'
};
function auth() {
gapi.auth.authorize(config, function() {
gapi.client.load('bigquery', 'v2');
$('#client_initiated').html('BigQuery client initiated');
});
}
</script>
</head>
<body>
<h2>BigQuery + JavaScript Example</h2>
<button id="auth_button" onclick="auth();">Authorize</button>
</body>
</html>
Running a Query and Retrieving the Result
Now that we have registered our application with Google and set up the parameters
we need for authorization, we can start making calls to the BigQuery API. But what
exactly does this mean? Essentially, all interaction with BigQuery takes place via a
REST-based API. Messages are sent to BigQuery in JSON format, and results and job
metadata are also returned as JSON objects.
BigQuery's API is jobs based, meaning that data-intensive operations such as que-
ries, loading data, and exporting require that an API call be made to insert that job
 
 
Search WWH ::




Custom Search