以下のコードの最後の2行の閉じかっこが赤色になり、エラーは出ないもののメッセージを送っても出力されません。かっこの数を確認しても問題がないのですが、どこに問題があるのでしょうか。
JavaScript
1function doPost(e) { 2 let event = JSON.parse(e.postData.contents).events[0]; 3 let replyToken= event.replyToken; 4 let userId = event.source.userId; 5 let nickname = getUserProfile(userId); 6 7 if(event.type == 'message') { 8 //weatherforecast 9 let user_id = '*************************:'; 10 let openweathermap_url = 'http://api.openweathermap.org/data/2.5/forecast'; 11 let openweathermap_appid = '********************'; 12 13 //openweathermapから日吉の天気予報を取得 14 let weatherforecast_finalurl = openweathermap_url + '?lat=35.5520&lon=139.6325&APPID=' + openweathermap_appid + '&units=metric'; 15 let response = UrlFetchApp.fetch(weatherforecast_finalurl); 16 let json = [JSON.parse(response.getContentText())]; 17 let answer = {}; 18 let reply_date = "invalid"; 19 let reply_temp = "invalid"; 20 let reply_feel = "invalid"; 21 let reply_cli = "invalid"; 22 23 for (let i = 0; i <= 7; i++){ 24 //気候コードを日本語に変換 25 let weather = JSON.stringify(json[0]["list"][3+i].weather[0].icon); 26 let text = ""; 27 if (weather == '"01n"' || weather == '"01d"'){ 28 text = '快晴'; 29 } 30 if (weather == '"02n"' || weather == '"02d"'){ 31 text = '晴れ'; 32 } 33 if (weather == '"03n"' || weather == '"03d"'){ 34 text = '曇り' 35 } 36 if (weather == '"04n"' || weather == '"04d"'){ 37 text = '曇り'; 38 } 39 if (weather == '"09n"' || weather == '"09d"'){ 40 text = '小雨'; 41 } 42 if (weather == '"10n"' || weather == '"10d"'){ 43 text = '雨'; 44 } 45 if (weather == '"11n"' || weather == '"11d"'){ 46 text = '雷雨'; 47 } 48 if (weather == '"13n"' || weather == '"13d"'){ 49 text = '雪'; 50 } 51 if (weather == '"50n"' || weather == '"50d"'){ 52 text = '霧'; 53 } 54 55 //日付を区切る 56 let str = JSON.stringify(json[0]["list"][3+i].dt_txt).split(" "); 57 let month = str[0].split("-")[1]; 58 let date = str[0].split("-")[2]; 59 let hour = str[1].split(":")[0]; 60 61 let res_date = month + "月" + date + "日" + hour + "時の気象情報"; 62 let res_temp = "気温: " + JSON.stringify(json[0]["list"][3+i].main.temp) + " ℃\n"; 63 let res_feel = "体感温度: " + JSON.stringify(json[0]["list"][3+i].main.feels_like) + " ℃\n"; 64 let res_cli = "気候: " + text; 65 66 //各時間にレスポンス代入 67 let obj_h = "res_"+hour; 68 answer[obj_h]["res_date"] = res_date; 69 answer[obj_h]["res_temp"] = res_temp; 70 answer[obj_h]["res_feel"] = res_feel; 71 answer[obj_h]["res_cli"] = res_cli; 72 }//for文閉じ 73 let userMessage = event.message.text; 74 if(userMessage.indexOf("%&%") != -1){ 75 let indi = "res_"+userMessage.split("%&%")[1]; 76 reply_date = answer[indi]["res_date"]; 77 reply_temp = answer[indi]["res_temp"]; 78 reply_feel = answer[indi]["res_feel"]; 79 reply_cli = answer[indi]["res_cli"]; 80 } 81 82 let url = 'https://api.line.me/v2/bot/message/reply'; 83 84 UrlFetchApp.fetch(url, { 85 'headers': { 86 'Content-Type': 'application/json; charset=UTF-8', 87 'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN, 88 }, 89 'method': 'post', 90 'payload': JSON.stringify({ 91 'replyToken': replyToken, 92 'messages': 93 [{ 94 "type":"flex", 95 "altText": "this is a flex message", 96 "contents": 97 { 98 "type": "bubble", 99 "header": { 100 "type": "box", 101 "layout": "vertical", 102 "contents": [ 103 { 104 "type": "text", 105 "text": "HIYOSHI Forecaster", 106 "size": "md", 107 "weight": "bold", 108 "style": "normal", 109 "align": "center" 110 } 111 ] 112 }, 113 "hero": { 114 "type": "image", 115 "url": "https://images.unsplash.com/photo-1486016006115-74a41448aea2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1947&q=80", 116 "margin": "none", 117 "size": "full", 118 "aspectMode": "cover", 119 "aspectRatio": "20:13" 120 }, 121 "body": { 122 "type": "box", 123 "layout": "vertical", 124 "contents": [ 125 { 126 "type": "text", 127 "text": reply_date, 128 "weight": "bold", 129 "size": "lg" 130 }, 131 { 132 "type": "separator", 133 "margin": "md" 134 }, 135 { 136 "type": "text", 137 "text": reply_temp, 138 "color": "#333333" 139 }, 140 { 141 "type": "text", 142 "text": reply_feel 143 }, 144 { 145 "type": "text", 146 "text": reply_cli 147 }, 148 { 149 "type": "box", 150 "layout": "vertical", 151 "contents": [ 152 { 153 "type": "button", 154 "action": { 155 "type": "uri", 156 "label": "View on website", 157 "uri": "http://weatherforecast.top" 158 }, 159 "color": "#ffffff" 160 } 161 ], 162 "backgroundColor": "#3F7A63", 163 "cornerRadius": "10px", 164 "spacing": "md" 165 } 166 ], 167 "position": "relative", 168 "spacing": "md" 169 }, 170 "styles": { 171 "header": { 172 "backgroundColor": "#fcb69f", 173 "separator": true 174 }, 175 "body": { 176 "backgroundColor": "#f5f5f5" 177 } 178 } 179 }//contents閉じ 180 }]//messages閉じ 181 })//paylord閉じ 182 })//fetch閉じ 183 return ContentService.createTextOutput( 184 JSON.stringify({'content': 'post ok'}) 185 ).setMimeType(ContentService.MimeType.JSON) 186 };//これが赤色になる。 187};//これが赤色になる。
回答1件
あなたの回答
tips
プレビュー