
I have updated the source code to address nested fields like links.website, delta.year.
function getCoinInfo(coin, field_name = 'rate', currency = 'USD', trigger) {
// Replace with your actual API key
const apiKey = 'de524e1a-2b81-48e8-86de-03a8046e88b2';
const url = 'https://api.livecoinwatch.com/coins/single';
const headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0',
'x-api-key': apiKey,
'Content-Type': 'application/json',
};
const payload = {
"currency": currency,
"code": coin,
"meta": true
};
const response = UrlFetchApp.fetch(url, {
"method": "post",
"headers": headers,
"payload": JSON.stringify(payload)
});
const data = JSON.parse(response.getContentText());
// Check if field_name contains '.', indicating a nested structure
if (field_name.includes('.')) {
// Split the field_name to traverse through the nested object
const fields = field_name.split('.');
let currentValue = data;
for (let i = 0; i < fields.length; i++) {
if (currentValue[fields[i]] !== undefined) {
currentValue = currentValue[fields[i]];
} else {
// Handle cases where the path does not exist
return `Field "${field_name}" not found`;
}
}
return currentValue;
} else {
// Direct access for non-nested fields
return data[field_name];
}
}
function force_update() {
var sheet = SpreadsheetApp.getActive().getActiveSheet();
var now = new Date();
// Format the date and time. Example: "YYYY-MM-dd HH:mm:ss"
// Adjust the format as needed.
// The time zone is set to "GMT" here, but you should replace it with your desired time zone.
var formattedDate = Utilities.formatDate(now, "GMT", "yyyy-MM-dd HH:mm:ss");
sheet.getRange("B2").setValue(formattedDate);
}

Lỗi
Exception: You do not have permission to call setValue (dòng 51)
Help me