У меня есть простой html и refresh.js (фрагмент кода ниже), который использует API-ключ для доступа к Google API для BigQuery. Но он возвращает ошибку после отправки запроса, где response = {code: 401, data: Array(1), message: "Login Required", error: {…}}
. Могу ли я знать, можно ли использовать ключ API для BigQuery или OAUTH2.0? Любая документация, которая указывает на это? Я новичок в JavaScript, а также в облаке Google. Пожалуйста, укажите мне, если есть какие-либо проблемы с кодом.
/* $(function() {} is just jQuery short-hand for
$(document).ready(function() { ... });
What it's designed to do (amongst other things) is ensure that your function
is called once all the DOM elements of the page are ready to be used.
*/
$(function() {
gapi.load('client', initClient);
});
var apiKey = '<api key>';
function initClient() {
gapi.client.init({
apiKey: apiKey,
discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/urlshortener/v1/rest']
}).then(initBigQuery)
}
function initBigQuery() {
gapi.client.load('bigquery', 'v2').then(
function() {
initAppl();
}
);
}
// Initialize application and start querying.
function initAppl(){
sendQuery(sqlStatement);
$.ajaxSetup({ cache: false });
}
function sendQuery(queryString){
var request = gapi.client.bigquery.jobs.query({
'query': queryString,
'timeoutMs': 30000,
'datasetId': dataSetId,
'projectId': projectId,
'useLegacySql':false
});
request.execute(function(response) {
checkJobStatus(response.jobReference.jobId);
});
}