大家好,
最近利用google app script透過line notify傳送google表單回覆,選項以及簡答類型的問題都可以傳到指定的群組沒有問題,但是上傳的圖片卻無法變成連結(不能點擊連結到雲端的圖片),情況如下圖:
以下是我從Boris大大那裡借來使用的程式碼:
//程式碼開始
function getFormData(e) {
var token = "umr19KVROBpXRmxkTznIMxRyZMuDkRVByiG8VULOmK1";
var form = FormApp.getActiveForm();
var currentItemResponses = e.response.getItemResponses();
var message = "\n\n";
for(var i = 0; i < currentItemResponses.length; i++) {
message += currentItemResponses[i].getItem().getTitle() + ":" + currentItemResponses[i].getResponse() + "\n\n";
}
sendLineNotify(message, token);
}
function sendLineNotify(message, token){
var options =
{
"method" : "post",
"payload" : {"message" : message},
"headers" : {"Authorization" : "Bearer " + token}
};
UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
}
//程式碼結束
請問為什麼應該要是連結的地方卻無法顯示連結呢?以及該如何才能解決這個問題?
再麻煩各位有空的話解答一下了,謝謝大家!!
修改後的程式碼如下:
function getFormData(e) {
var token = "umr19KVROBpXRmxkTznIMxRyZMuDkRVByiG8VULOmK1";
var form = FormApp.getActiveForm();
var currentItemResponses = e.response.getItemResponses();
var message = "\n\n";
for(var i = 0; i < currentItemResponses.length; i++) {
var item = currentItemResponses[i].getItem();
var response = currentItemResponses[i].getResponse();
if (item.getType() == FormApp.ItemType.IMAGE) {
var file = DriveApp.getFileById(response[0].getId());
var blob = file.getBlob();
var options = {
"method" : "post",
"payload" : blob.getBytes(),
"headers" : {"Authorization" : "Bearer " + token, "Content-Type": blob.getContentType()}
};
UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
} else {
message += item.getTitle() + ":" + currentItemResponses[i].getResponse() + "\n\n";
}
}
sendLineNotify(message, token);
}
試試看
中午12:00:56 錯誤
TypeError: Cannot read properties of undefined (reading 'response')
getFormData @ 程式碼.gs:4
請問這是甚麼意思?
for(var i = 0; i < currentItemResponses.length; i++) {
message += currentItemResponses[i].getItem().getTitle() + ":" + currentItemResponses[i].getResponse() + "\n\n";
}
想請問一下這個程式碼是甚麼意思??
我想要改成只顯示1個問題及答案,不知道要怎麼改??