I am trying to retrieve data (Image) from the Google Spreadsheet in Javascript:
Image of the Error:
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));
}
});
I am receiving an error on the code.
You want to retrieve hyperlinks from "Sheet1" of a Spreadsheet. If my understanding is correct, how about this modification?
sheets/data/rowData/values/hyperlink
is used as the fields.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));
}
});
When no error occurs, the object like below is returned.
{
"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));
. If the error occurs at this line, please try the following script.
console.log(JSON.stringify(result.data, null, 2));
If I misunderstand your question, I'm sorry.
I figure it out:
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;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.