<やりたいこと>
文字起こしLINEアプリを作りたい。
<使用しているもの>
LINE DEVELOPERS
Google Apps Script
<エラー>
ステートメントの前に:がありません(2行目)
当方プログラミング初学者です。
エラーにつまづき、はや1日・・・。
公開すらできず手こずっております。
1function doPost(e) { 2 const LINE_ACCESS_TOKEN = ${ACCESS_TOKEN}; 3 const lineJson = JSON.parse(e.postData.contents); 4 const replyToken = lineJson.events[0].replyToken; 5 const messageId = lineJson.events[0].message.id; 6 const lineImageUrl = "https://api.line.me/v2/bot/message/"+ messageId + "/content/"; // バイナリファイルの画像が取得できるエンドポイント 7 console.log(lineImageUrl); 8 const lineImageResponse = UrlFetchApp.fetch(lineImageUrl, { 9 'headers':{ 10 'Content-Type':'application/json; charset=UTF-8', 11 "Authorization": "Bearer " + LINE_ACCESS_TOKEN 12 }, 13 'method':'get' // ここでメソッドを指定 14 }) 15 .getContent(); 16 const lineImageBlob = Utilities.base64Encode(lineImageResponse); // base64エンコーディング 17 console.log(lineImageBlob); 18/** 19 const url = "https://dividable.net/wp/wp-content/uploads/2019/01/sample2.png"; 20 const imageResponse = UrlFetchApp.fetch(url, { 21 'headers':{ 22 'Content-Type': 'application/json; charset=UTF-8', 23 }, 24 'method': 'get'//ここでメソッドを指定 25 26 }) 27 .getContent(); 28 const imageBlob = Utilities.base64Encode(imageResponse); 29 **/ 30 const API_KEY = ${API_KEY}; 31 const visionRequestUrl = 'https://vision.googleapis.com/v1/images:annotate?key=' + API_KEY; //URLを追加 32 const payload = JSON.stringify({ 33 "requests":[ 34 { 35 "image":{ 36 "content": imageBlob 37 }, 38 "features":[ 39 { 40 "type": "TEXT_DETECTION", 41 "maxResults":1 42 } 43 ] 44 } 45 ] 46 }); 47 const visionTextResponse = UrlFetchApp.fetch(visionRequestUrl, { 48 method:"POST", 49 contentType:"application/json", 50 payload : payload, 51 }) 52 .getContentText(); 53 54 const visionTextJson = JSON.parse(visionTextResponse); 55 const visionText = visionTextJson.responses[0].fullTextAnnotation. 56 text; //responses > fullTextAnnotation > text を取得 57 58 const messages =[ 59 { 60 "type":"text", 61 "text":visionText 62 } 63 ] 64 UrlFetchApp.("https://api.line.me/v2/bot/message/reply",{ 65 "header":{ 66 "Content-Type":"application/json; charset=UTF-8", 67 "AAuthorization":"Bearer " + LINE_ACCESS_TOKEN, 68 }, 69 "method":"post", 70 "payload":JSON.stringify({ 71 "replyToken":replyToken, 72 "messages":messages, 73 }) 74 }); 75 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/08 05:17
2019/04/08 05:36
2019/04/08 09:18