我正在尝试使用Javascript从Google Spreadsheet检索数据(图像)吗?
错误图片: enter image description here
sheets.spreadsheets.values.get({
auth: jwtClient,
spreadsheetId: SPREADSHEET_ID,
range: 'Sheet1',
includeValuesInResponse: true,
}, function(err, result) {
if(err) {
// Handle error.
console.log(err);
} else {
console.log('%d cells appended.', JSON.stringify(result, null, 2));
}
});
我收到代码错误。
答案 0 :(得分:0)
您要从电子表格的“ Sheet1”中检索超链接。如果我的理解是正确的,那么该修改如何?
sheets/data/rowData/values/hyperlink
用作字段。sheets.spreadsheets.get({
auth: jwtClient,
spreadsheetId: SPREADSHEET_ID,
ranges: 'Sheet1',
fields: "sheets/data/rowData/values/hyperlink",
}, function(err, result) {
if (err) {
// Handle error.
console.log(err);
} else {
console.log('%d cells appended.', JSON.stringify(result, null, 2));
}
});
没有错误发生时,将返回如下所示的对象。
{
"sheets": [
{
"data": [
{
"rowData": [
{
"values": [
{
"hyperlink": "https://sample.com/img1.jpg"
}
]
},
{
"values": [
{
"hyperlink": "https://sample.com/img2.jpg"
}
]
},
{},
{},
{},
]
}
]
}
]
}
console.log('%d cells appended.', JSON.stringify(result, null, 2));
。如果此行发生错误,请尝试以下脚本。
console.log(JSON.stringify(result.data, null, 2));
如果我误解了你的问题,对不起。
答案 1 :(得分:0)
我知道了:
async.series([
function makeAnAuthorizedApiCall(callback){
var {google} = require('googleapis');
var sheets = google.sheets('v4');
const storage = new Storage({ projectId: PROJECT_ID });
const jsonCredentialsFile = storage.bucket(BUCKET_NAME).file(SERVICE_ACCT_JSON_FILE);
retrieveFromGCStorage(jsonCredentialsFile).then(creds => {
console.log("Credentials successfully obtained from Google Cloud Storage");
var jwtClient = new google.auth.JWT(
creds.client_email,
null,
creds.private_key,
API_SCOPES, // an array of auth scopes
null
);
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
}
});