Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:48:59+00:00 2026-06-11T12:48:59+00:00

I’m new to BigQuery (and to actually using Google API’s whatsoever). Trying to read

  • 0

I’m new to BigQuery (and to actually using Google API’s whatsoever). Trying to read a table from JavaScript code, I am clueless as to how this should be accomplished, given my current experience and the state of documentation and lack of sample code that I could locate. It is a table I’ve already populated through Google’s online console, and it can be seamlessly queried there in that online console.

Using Google’s beta JavaScript library for BigQuery, my code receives the error object that follows my actual code. It fails on getting the table handle, which is required per my understanding for actually issuing a call to read the table. I’m quite sure my code is incorrect in more than one way in terms of what API calls I’m using, for the sake of getting to read a table’s content.

Code

gapi.client.load('bigquery', 'v2', function() {
    gapi.client.setApiKey('My Key for browser apps here...');
    var request = gapi.client.bigquery.tables.get({'id': 'My-dataset-name.My-table-name'});
    request.execute(function(response) {console.log(response, JSON.stringify(response, null))});
});

Result

{“code”:401,”message”:”Login Required”,”data”:[{“domain”:”global”,”reason”:”required”,”message”:”Login Required”,”locationType”:”header”,”location”:”Authorization”}]

I am short of deducing whether an API key (‘Key for browser apps’ as showing in my dashboard) is sufficient for authorizing access for reading data, as well as what is the syntax that should be used for the tables.get directive. Given the multitude of dimensions using this for the first time presents, I doubt I’d find out how to use the API without setting my hair on fire. What is a detailed explanation for those last two points, and what would working sample code be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:49:01+00:00Added an answer on June 11, 2026 at 12:49 pm

    The following sample is HTML/JavaScript code for querying BigQuery, and populating the result in a map generated by Google Chart Tools. You need to update with your project ID and client ID– and register your app in the APIs console in order to use this.

    This uses the US birth statistics (natality) sample data set documented here:
    https://developers.google.com/bigquery/docs/dataset-natality

    It uses the Google APIs Client Library for JavaScript to handle authorization and API requests to BigQuery.

    The user will be directed through an OAuth approval flow the first time accessing this page (for permission to the OAuth scope defined in the ‘config’). They have to be an authorized user of the indicated project (so the project’s quota/billing can be implemented). This OAuth authorization will cause a popup to appear if the user hasn’t recently authorized, though they won’t be required to grant authorization again if authorization was previously granted. You can look into “immediate mode” if you need it to happen more transparently.

    <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 type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['geochart']});
    </script>
    <script>
      // UPDATE TO USE YOUR PROJECT ID AND CLIENT ID
      var project_id = '605902584318';
      var client_id = '605902584318.apps.googleusercontent.com';
    
      var config = {
        'client_id': client_id,
        'scope': 'https://www.googleapis.com/auth/bigquery'
      };
    
      function runQuery() {
       var request = gapi.client.bigquery.jobs.query({
          'projectId': project_id,
          'timeoutMs': '30000',
          'query': 'SELECT state, AVG(mother_age) AS theav FROM [publicdata:samples.natality] WHERE year=2000 AND ever_born=1 GROUP BY state ORDER BY theav DESC;'
        });
        request.execute(function(response) {     
            console.log(response);
            var stateValues = [["State", "Age"]];
            $.each(response.result.rows, function(i, item) {
              var state = item.f[0].v;
              var age = parseFloat(item.f[1].v);
              var stateValue = [state, age];
              stateValues.push(stateValue);
            });  
            var data = google.visualization.arrayToDataTable(stateValues);
            var geochart = new google.visualization.GeoChart(
                document.getElementById('map'));
            geochart.draw(data, {width: 556, height: 347, resolution: "provinces", region: "US"});
        });
      }
    
      function auth() {
        gapi.auth.authorize(config, function() {
            gapi.client.load('bigquery', 'v2', runQuery);
            $('#client_initiated').html('BigQuery client initiated');
        });
        $('#auth_button').hide();
      }
    </script>
    </head>
    
    <body>
    <h2>Average Mother Age at First Birth in 2000</h2>
    <button id="auth_button" onclick="auth();">Authorize</button>
    <button id="query_button" style="display:none;" onclick="runQuery();">Run Query</button>
    <div id="map"></div>
    </body>
    </html>
    

    Note: if you’re trying to have the queries charged to your quota/bill without having the user go through OAuth authorization, you’ll need to setup a simple server-side proxy which proxies your requests to the API. Would be fairly simple to do this on App Engine with service accounts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.