var instancia = 'mastodon.madrid';
var bootToken = '1d04U1Wnc0h-xxxxxxXXXX-_YYYY';
function sendMastodon() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
const rows = sheet.getRange(2,1,100,2).getValues()
var candidates = []
for( var r=0; r<rows.length; r++){
const row = rows[r];
if( row[0].toString() !== ""){
continue;
}
if( row[1].toString().trim().length == 0){
continue;
}
candidates.push(row[1])
}
const toot = candidates[Math.floor(Math.random() * candidates.length)];
var payload = {
'status': toot,
}
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload),
'headers': {
'Authorization': `Bearer ${bootToken}`
},
'muteHttpExceptions':true
};
Logger.log(payload)
var url = `https://${instancia}/api/v1/statuses`;
const resp = UrlFetchApp.fetch(url, options);
Logger.log(resp)
}