使用API可以在javascript中获取或插入BigQuery的数据吗?
它不起作用。 (请参阅网站https://developers.google.com/api-client-library/javascript/samples/samples)
<html>
<head>
<script src="https://apis.google.com/js/api.js"></script>
<script>
function start() {
gapi.client.init({
'apiKey': 'mykey',
}).then(function() {
return gapi.client.request({
'path' : 'https://www.googleapis.com/bigquery/v2/projects/projectId/queries/jobId',
'method' : 'GET'
'params' : {'projectId':'myid', 'jobId':'myid'}
});
}).then(function(response) {
console.log(response.result);
}, function(reason) {
console.log('Error: ' + reason.result.error.message);
});
};
gapi.load('client', start);
</script>
</head>
<body>
<div id="results"></div>
</body>
</html>
答案 0 :(得分:0)
// Import the Google Cloud client library
const {BigQuery} = require('@google-cloud/bigquery');
async function queryStackOverflow() {
// Queries a public Stack Overflow dataset.
// Create a client
const bigqueryClient = new BigQuery();
// The SQL query to run
const sqlQuery = `SELECT repo.name FROM githubarchive.year.2019
where repo.name LIKE '%googlemaps%'
or repo.name LIKE '%google-maps%'
or repo.name LIKE '%google-maps-api%'
or repo.name LIKE '%googlemapsapi%'
Group by
repo.name`;
const options = {
query: sqlQuery,
};
// Run the query
const [rows] = await bigqueryClient.query(options);
console.log(rows);
}
queryStackOverflow();