Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running a query using @google-cloud/bigquery lib with oAuth2 key not working #481

Closed
szxyks opened this issue Jun 13, 2019 · 2 comments
Closed
Assignees
Labels
api: bigquery Issues related to the googleapis/nodejs-bigquery API. 🚨 This issue needs some love. status: duplicate Duplicate. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@szxyks
Copy link

szxyks commented Jun 13, 2019

Running the following code :

if (!global._babelPolyfill) {
  var a = require("babel-polyfill")
}

//import BigQuery from '@google-cloud/bigquery'
const {BigQuery} = require('@google-cloud/bigquery');

describe('Check google-cloud', function () {
  it('download query using google code', async function () {
    this.timeout(50000000000);
    let result = await googleWay()
  });

  async function googleWay () {
    const bigqueryClient = new BigQuery({
      token: 'client-token',
      projectId: 'project-name'
    });

    const query = `SELECT name 
      FROM \`bigquery-public-data.usa_names.usa_1910_2013\` 
      WHERE state = 'TX' 
      LIMIT 10`;

    const options = {
      query: query,
      location: 'US',
    };

    const [job] = await bigqueryClient.createQueryJob(options);
    console.log(`Job ${job.id} started.`);

    const [rows] = await job.getQueryResults();
    console.log('Rows:');
    rows.forEach(row => console.log(row));
  }
});

Lead to the following error message:

{ Error: Multiple errors occurred during the request. Please see the `errors` array for complete details. 

1. Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project. 
2. Login Required. 


at Util.parseHttpRespBody (/Users/tamirklein/superquery/bd/lambda/node_modules/@google-cloud/common/build/src/util.js:191:38) 
at Util.handleResp (/Users/tamirklein/superquery/bd/lambda/node_modules/@google-cloud/common/build/src/util.js:135:117) 
at retryRequest (/Users/tamirklein/superquery/bd/lambda/node_modules/@google-cloud/common/build/src/util.js:417:22) 
at onResponse (/Users/tamirklein/superquery/bd/lambda/node_modules/retry-request/index.js:200:7) 
at /Users/tamirklein/superquery/bd/lambda/node_modules/teeny-request/src/index.ts:237:19 
at <anonymous> 
at process._tickCallback (internal/process/next_tick.js:188:7) 
code: 401, 
errors: 
[ { message: 'Login Required.', 
domain: 'global', 
reason: 'required', 
location: 'Authorization', 
locationType: 'header' } ], 
response: undefined, 
message: 'Multiple errors occurred during the request. Please see the `errors` array for complete details.\n\n 1. Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.\n 2. Login Required.\n\n' } 

However, when using the same code with a service account - there's no issue

How to access run a query in BigQuery using Nodejs through Token

FYI: I generated my token from here: https://developers.google.com/oauthplayground/

@callmehiphop
Copy link
Contributor

@sd0m1n1ck this is actually a known issue (of sorts) with our auth library. I'm not sure what kind of ETA we are looking at, but I would subscribe to #418 for any updates. I apologize for the inconvenience.

@callmehiphop callmehiphop added status: duplicate Duplicate. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jun 13, 2019
@MartinSahlen
Copy link

@sd0m1n1ck I managed to get it working like this: #68 (comment)

@google-cloud-label-sync google-cloud-label-sync bot added the api: bigquery Issues related to the googleapis/nodejs-bigquery API. label Jan 31, 2020
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/nodejs-bigquery API. 🚨 This issue needs some love. status: duplicate Duplicate. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants