title: Authenticating to BigQuery REST API via OAuth2 from Node.js
body: <p>Newbie trying to figure out how to get a Node.js application to authenticate and query Google BigQuery, trying to adapt <a href="https://developers.google.com/bigquery/articles/gettingstartedwithjava#createandauth" rel="nofollow">this CodeLab tutorial from Java</a>.  What step might i be missing?</p>
  
  <p>First I create this Oauth2 URL using my clientid:</p>
  
  <pre><code>https://accounts.google.com/o/oauth2/auth?
      client_id=1047877053699-den6kbs4v3f2bft6clonsirkj1pc7t6j.apps.googleusercontent.com
      &amp;scope=https://www.googleapis.com/auth/bigquery
      &amp;redirect_uri=http://localhost:3000/oauth2callback
      &amp;access_type=offline
      &amp;response_type=code
  </code></pre>
  
  <p>This successfully reaches Google, which prompts </p>
  
  <blockquote>
    <p><strong>A third party service is requesting permission to access your Google Account.</strong></p>
  </blockquote>
  
  <p>Agreeing that generates a second prompt:  </p>
  
  <blockquote>
    <p>Nodejs_Test is requesting permission to: 
    View and manage your data in Google BigQuery</p>
  </blockquote>
  
  <p>Agreeing to that, the callback URL is called, with a parameter <code>accessToken</code>.</p>
  
  <p>I <em>think</em> the following url should list tables in my BigQuery project/dataset:</p>
  
  <p><a href="https://www.googleapis.com/bigquery/v2/projects/1047877053699/datasets/visits&amp;accessToken=4%2FC196NizZwlNgWSt5oNqQwendmLNW.0vgUrlGJ6kMRshQV0ieZDApig3NfcgI" rel="nofollow">https://www.googleapis.com/bigquery/v2/projects/1047877053699/datasets/visits&amp;accessToken=4%2FC196NizZwlNgWSt5oNqQwendmLNW.0vgUrlGJ6kMRshQV0ieZDApig3NfcgI</a></p>
  
  <p>But calling with or  without the accessToken returns the following message that "Login Required".</p>
  
  <pre><code> {
   "error": {
    "errors": [
     {
      "domain": "global",
      "reason": "required",
      "message": "Login Required",
      "locationType": "header",
      "location": "Authorization"
     }
    ],
    "code": 401,
    "message": "Login Required"
   }
  }
  </code></pre>
  
  <p>I know you can't repeat the code because of permissions, expired tokens, etc.  But I wonder what step I might be missing conceptually.</p>