プログラミング初心者ですが、GASからLINE公式アカウント経由で友だちにメッセージを送信することを試みております。
以下、ネットの拾い物を少々いじったものとなります。
function postMessage() { const url = 'https://api.line.me/v2/bot/message/push'; const token = 'チャネルアクセストークン'; //チャネルアクセストークン var spreadsheet = SpreadsheetApp.openById("スプシアドレス"); var sheet_userlist = spreadsheet.getSheetByName('userlist'); let userId = sheet_userlist.getRange("B2").getValues(); let message = sheet_userlist.getRange("C2").getValues(); console.log(userId); //確認用 console.log(message); //確認用 const postData = { "to": userId, "messages": [{ "type": "text", "text": message }] } const params = { method: 'post', contentType: 'application/json', headers: { Authorization: 'Bearer ' + token }, payload: JSON.stringify(postData) }; UrlFetchApp.fetch(url, params); }
以下のようにユーザーIDとメッセージを直接書き込めば問題なく送信できますが、
const postData = {
"to": "ユーザーID",
"messages": [{
"type": "text",
"text": "メッセージ"
}]
}
上記のコードのように、スプレッドのセルからもってきた変数でユーザーIDとメッセージ内容を指定すると、こちらのエラーが返ってきます。
Exception: Request failed for https://api.line.me returned code 400. Truncated server response: {"message":"The property, 'to', in the request body is invalid (line: 1, column: 7)"} (use muteHttpExceptions option to examine full response)
解決策をご教授頂けますと大変幸いでございます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/05/02 02:49