in Education by
I've been putzing with trying to call the jobs.Insert bigquery rest api endpoint with node (the jobs.Insert method does not seem to be exposed in the bigquery node library). I've got the Service-to-Service stuff set up so that I can successfully call the methods that the bigquery node library has (create the json file that has the private key, etc. in it for service-to-service calls). As far as I can tell, I should be able to do call the rest api directly with a signed jwt as the bearer token without having to go through a two-step OAuth process. I've got stuff to sign a jwt but still getting authentication errors trying to call the raw api just with curl (as a first step) via something like curl -H "Authorization: Bearer my_signed_jwt" https://www.googleapis.com/bigquery/v2/projects/my_project_id/datasets ("Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential." Does anyone have an example of doing this? Might be missing just a simple thing that a working example would make obvious. thanks JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use this working example which does Init query object Init oAuth2 object Call bigQuery.Jobs.insert if (!global._babelPolyfill) { var a = require("babel-polyfill") } import {google} from 'googleapis' let bigQuery = google.bigquery("v2") describe('Check API', async () => { it('Test query', async () => { let result = await test('panada') }) async function test(p1) { try { let query = `SELECT url FROM \`publicdata.samples.github_nested\` WHERE repository.owner = 'panada'` let auth = getBasicAuthObj() auth.setCredentials({ access_token: "myAccessToken", refresh_token: "myRefreshToken" }) let request = { "projectId": "myProject", auth, "resource": { "projectId": "myProject", "configuration": { "query": { query, "useLegacySql": false }, "dryRun": false } } } console.log(`query is: ${query}`) let result = await callBQ(request) //Check JOB status to make sure it's done console.log(`result is: ${JSON.stringify(result.data)}`) result.forEach((row, index) => { console.log(`row number ${index}, url is: ${row.url}`) }) } catch (err) { console.log("err", err) } } /** * Call BigQuery jobs.insert * @param request * @returns {Promise} */ async function callBQ(request) { debugger console.log("request", request) try { let result = await bigQuery.jobs.insert(request, request)//, (err, results) => { console.log(`All good.....`) return result } catch (e) { console.log(`Failed to run query: ${e}`) } } /** * Create oAuth object * @returns {OAuth2Client} */ function getBasicAuthObj() { let clientId = 'myClientId' let clientSecret = 'mySecret' let redirectUrl = 'url' return new google.auth.OAuth2( clientId, clientSecret, redirectUrl ) } }) note: You need to add this line to your package.json "googleapis": "34.0.0"

Related questions

0 votes
    i'm trying to test with jest this route on my node microservice. At the initalisation of my microservice ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    The napi_create_date function appeared in Node.js starting with 11.11.0 version. https://nodejs.org/api/n- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I'm trying to debug my nodejs app using node-inspector. But Google Chrome doesn't show the code. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    I have been looking at using the ssh2 module for sftp shipping of logs. However the cloud service hosting ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    so i'm reviewing and practicing making rest api with node mongoose and express. I'm having problem making ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I'm trying to use node to print the Serial from Arduino uno connected to USB I have a file script ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    Quick Summary of my question: Does Gulp 3.6.0 dest() handle glob-base the same way as 4.0.0? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do here is use the 2 functions but I don't know how to use both of them ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do here is use the 2 functions but I don't know how to use both of them ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I'm used to v3 node botbuilder sdk so I have a middleware where I look at the dialog stack and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    What is a Node?...
asked Nov 20, 2020 in Education by Editorial Staff
0 votes
    I am trying to write some stuff in a file using reactJS and nodeJs but it doesnt work. Here is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to write some stuff in a file using reactJS and nodeJs but it doesnt work. Here is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I am running my nodejs app by npm start I just installed nodemon by sudo npm install -g nodemon ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    Trying to implement OCR in the bank environment but the challenge is, we don't have access to an internet connection ... in our bank. Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
...