Google Apps Script ( , , ).
JSON, /x -www-form-urlencoded, URL- URL-, base64, https://www.base64-image.de/.
function doGet(e) {
return ContentService.createTextOutput("Authorization: Bearer " + ScriptApp.getOAuthToken())
}
var REQUIRED_PARAMS = [
'spreadsheetid',
'sheetname',
'imageurl',
'column',
'row'
];
function doPost(e) {
var result = {
status: "ok",
defaultMessage: "Image inserted."
}
try {
var params = (e.postData && e.postData.type == "application/x-www-form-urlencoded") ? e.parameter
: (e.postData && e.postData.type == "application/json") ? JSON.parse(e.postData.contents)
: undefined;
if (!params) throw new Error('Unsupported content-type, must be either application/x-www-form-urlencoded or application/json.');
REQUIRED_PARAMS.forEach(function(requiredParam) {
if (!params[requiredParam]) throw new Error('Missing required parameter ' + requiredParam);
});
SpreadsheetApp.openById(params.spreadsheetid).getSheetByName(params.sheetname).insertImage(params.imageurl, params.column, params.row);
} catch(e) {
console.error(e);
result.status = "error";
result.error = e;
result.defaultMessage = e.message;
}
return ContentService.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON)
}
, :
Postman (, cookie) URL- - . , Oauth, ScriptApp.getOAuthToken(), https://www.googleapis.com/auth/drive - .
:
{
"timeZone": "America/Los_Angeles",
"dependencies": {
},
"webapp": {
"access": "ANYONE",
"executeAs": "USER_ACCESSING"
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
}
Blob insertImage(), URL- insertImage URL- Base 64, , , API- Sheets .
Script () :
https://script.google.com/d/1JvFwemL45x3orxFiJf_Gye-JWXaFlzA_MysJsQx06LsH8M2psa9i1H99/edit?usp=sharing
And it is also publicly deployed here, wo if you want to test it without deploying your own on it:
https://script.google.com/a/tillerhq.com/macros/s/AKfycbzjFgIrgCfZTvOHImuX54G90VuAgmyfz2cmaKjrsNFrTzcLpNk0/exec