Google-Big Query with JavaScript -
I'm kind of new with Google APIs and Javascript,
Any one instance or Tutorials How can I add the Google-Big Query API by using Javascript and load the data from a sample table to a simple HTML page.
Thanks in advance for this.
Try to do something like this:
& lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "https://apis.google.com/js/client.js" & gt; & Lt; / Script & gt; & Lt; Script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; // user submitted variables var project_id = 'XXXXXXXXXXX'; Var client_id = 'XXXXXXXXXXXXXXXXXX.apps.googleusercontent.com'; Var config = {'client_id': client_id, 'scope': 'https://www.googleapis.com/auth/bigquery'}; Function ShowProject () {var request = gapi.client.bigquery.projects.list (); Request.execute (function (response) {$ ('# result_box') .html (JSON.stringify (response, empty))}); } Function shadow () {var request = gapi.client.bigquery.datasets.list ({'projectId': 'publicdata'}); Request.execute {$ ('# result_box') .html (JSON.stringify (response.result.datasets, null));}; } Function runQuery () {var request = gapi.client.bigquery.jobs.query ({'projectId': project_id, 'timeoutMs': '30000', 'query': 'SELECT TOP' as the language (repository_language, 5) Select [publicdata: samples.github_timeline] WHERE repository_language! = ""; '}) From calculation as COUNT (*); Request.execute (function) {console.log (response); $ ('# result_box') .html (JSON.stringify (response.result.rows, null))}); } Function auth () {gapi.auth.authorize (config, function () {gapi.client.load ('bigquery', 'v2'); $ ('# client_initiated') .html ('BigQuery client initiate'); $ ('#Auth_button') Feeds (); $ ('# projects_button'). FadeIn (); $ ('# dataset_button'). FadeIn (); $ ('# query_button'). FadeIn ();}) ; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; H2 & gt; Large sign + JavaScript example & lt; / H2 & gt; & Lt; Button id = "auth_button" onclick = "auth ();" & Gt; Authorize & lt; / Button & gt; & Lt; Div id = "client_initiated" & gt; & Lt; / Div & gt; & Lt; Button id = "projects_button" style = "display: none;" Onclick = "showProjects ();" & Gt; Show Project & lt; / Button & gt; & Lt; Button id = "dataset_button" style = "display: none;" Onclick = "showDatasets ();" & Gt; Show Dataset & lt; / Button & gt; & Lt; Button ID = "query_button" style = "display: none;" Onclick = "runQuery ();" & Gt; Run query & lt; / Button & gt; & Lt; Div id = "result_box" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Comments
Post a Comment