質問編集履歴
17
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -106,67 +106,4 @@
|
|
106
106
|
|
107
107
|
**補足情報**
|
108
108
|
使用書籍:独学プログラマーのためのAIアプリ開発がわかる本
|
109
|
-
116ページから141ページまではできましたが、142ページから進んでいないです。
|
109
|
+
116ページから141ページまではできましたが、142ページから進んでいないです。
|
110
|
-
|
111
|
-
**文字起こし君のサンプルコード**
|
112
|
-
```ここに言語を入力
|
113
|
-
function doPost(e) {
|
114
|
-
const LINE_ACCESS_TOKEN = ${ACCESS_TOKEN};
|
115
|
-
const lineJson = JSON.parse(e.postData.contents);
|
116
|
-
const replyToken = lineJson.events[0].replyToken;
|
117
|
-
const messageId = lineJson.events[0].message.id;
|
118
|
-
const lineImageUrl = "https://api.line.me/v2/bot/message/" + messageId + "/content/";
|
119
|
-
const lineImageResponse = UrlFetchApp.fetch(lineImageUrl, {
|
120
|
-
'headers': {
|
121
|
-
'Content-Type': 'application/json; charset=UTF-8',
|
122
|
-
"Authorization": "Bearer " + LINE_ACCESS_TOKEN
|
123
|
-
},
|
124
|
-
'method': 'get'
|
125
|
-
})
|
126
|
-
.getContent();
|
127
|
-
const lineImageBlob = Utilities.base64Encode(lineImageResponse);
|
128
|
-
const API_KEY = ${API_KEY};
|
129
|
-
const visionRequestUrl = 'https://vision.googleapis.com/v1/images:annotate?key=' + API_KEY;
|
130
|
-
const payload = JSON.stringify({
|
131
|
-
"requests":[
|
132
|
-
{
|
133
|
-
"image": {
|
134
|
-
"content": lineImageBlob
|
135
|
-
},
|
136
|
-
"features": [
|
137
|
-
{
|
138
|
-
"type": "TEXT_DETECTION",
|
139
|
-
"maxResults": 1
|
140
|
-
}
|
141
|
-
]
|
142
|
-
}
|
143
|
-
]
|
144
|
-
});
|
145
|
-
const visionTextResponse = UrlFetchApp.fetch(visionRequestUrl, {
|
146
|
-
method: "POST",
|
147
|
-
contentType: "application/json",
|
148
|
-
payload: payload,
|
149
|
-
})
|
150
|
-
.getContentText();
|
151
|
-
const visionTextJson = JSON.parse(visionTextResponse);
|
152
|
-
const visionText = visionTextJson.responses[0].fullTextAnnotation.
|
153
|
-
text;
|
154
|
-
const messages = [
|
155
|
-
{
|
156
|
-
"type":"text",
|
157
|
-
"text": visionText
|
158
|
-
}
|
159
|
-
]
|
160
|
-
UrlFetchApp.fetch("https://api.line.me/v2/bot/message/reply", {
|
161
|
-
"headers": {
|
162
|
-
"Content-Type": "application/json; charset=UTF-8",
|
163
|
-
"Authorization": "Bearer " + LINE_ACCESS_TOKEN,
|
164
|
-
},
|
165
|
-
"method": "post",
|
166
|
-
"payload": JSON.stringify({
|
167
|
-
"replyToken": replyToken,
|
168
|
-
"messages": messages,
|
169
|
-
})
|
170
|
-
});
|
171
|
-
}
|
172
|
-
```
|
16
試みたことの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -101,7 +101,7 @@
|
|
101
101
|
**試みたこと**
|
102
102
|
・${API_KEY}は与えられたものに変更した。(""を付けて)
|
103
103
|
・Googleの拡張サービスのDrive APIを有効にした。
|
104
|
-
・LINE BOTをGASで作成(https://qiita.com/t_gata/items/897936761695124ef920)を参照した。
|
104
|
+
・LINE BOTをGASで作成(https://qiita.com/t_gata/items/897936761695124ef920)を参照し、少し時間をおいたが、解決していない。
|
105
105
|
・TypeError: undefined からプロパティ「postData」を読み取るための解決策(https://teratail.com/questions/181927)を参照し、実行した。
|
106
106
|
|
107
107
|
**補足情報**
|
15
補足情報の追加
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
14
補足情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
const lineJson = JSON.parse(e.postData.contents);
|
2
|
+
この部分のコードのpostDataの読み取りをするにはどのようにすれば良いかアドバイスをいただきたいです。
|
3
|
+
よろしくお願いいたします。
|
4
|
+
|
5
|
+
言語:JavaScript
|
6
|
+
環境:Goole Apps Script
|
1
7
|
```ここに言語を入力
|
2
8
|
function doPost(e) {
|
3
9
|
const url = "https://dividable.net/wp/wp-content/uploads/2019/01/sample2.png";
|
13
試みたことの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -96,6 +96,7 @@
|
|
96
96
|
・${API_KEY}は与えられたものに変更した。(""を付けて)
|
97
97
|
・Googleの拡張サービスのDrive APIを有効にした。
|
98
98
|
・LINE BOTをGASで作成(https://qiita.com/t_gata/items/897936761695124ef920)を参照した。
|
99
|
+
・TypeError: undefined からプロパティ「postData」を読み取るための解決策(https://teratail.com/questions/181927)を参照し、実行した。
|
99
100
|
|
100
101
|
**補足情報**
|
101
102
|
使用書籍:独学プログラマーのためのAIアプリ開発がわかる本
|
12
補足情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -87,7 +87,7 @@
|
|
87
87
|
```
|
88
88
|
にすると
|
89
89
|
```ここに言語を入力
|
90
|
-
TypeError: undefined からプロパティ「postData」を読み取れません。(行
|
90
|
+
TypeError: undefined からプロパティ「postData」を読み取れません。(行 2、ファイル「コード」)
|
91
91
|
```
|
92
92
|

|
93
93
|
とエラーが出てきます。
|
11
画像追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -89,6 +89,7 @@
|
|
89
89
|
```ここに言語を入力
|
90
90
|
TypeError: undefined からプロパティ「postData」を読み取れません。(行 3、ファイル「コード」)
|
91
91
|
```
|
92
|
+

|
92
93
|
とエラーが出てきます。
|
93
94
|
|
94
95
|
**試みたこと**
|
10
補足情報の追加、インデントの調整
title
CHANGED
File without changes
|
body
CHANGED
@@ -97,4 +97,68 @@
|
|
97
97
|
・LINE BOTをGASで作成(https://qiita.com/t_gata/items/897936761695124ef920)を参照した。
|
98
98
|
|
99
99
|
**補足情報**
|
100
|
-
使用書籍:独学プログラマーのためのAIアプリ開発がわかる本
|
100
|
+
使用書籍:独学プログラマーのためのAIアプリ開発がわかる本
|
101
|
+
116ページから141ページまではできましたが、142ページから進んでいないです。
|
102
|
+
|
103
|
+
**文字起こし君のサンプルコード**
|
104
|
+
```ここに言語を入力
|
105
|
+
function doPost(e) {
|
106
|
+
const LINE_ACCESS_TOKEN = ${ACCESS_TOKEN};
|
107
|
+
const lineJson = JSON.parse(e.postData.contents);
|
108
|
+
const replyToken = lineJson.events[0].replyToken;
|
109
|
+
const messageId = lineJson.events[0].message.id;
|
110
|
+
const lineImageUrl = "https://api.line.me/v2/bot/message/" + messageId + "/content/";
|
111
|
+
const lineImageResponse = UrlFetchApp.fetch(lineImageUrl, {
|
112
|
+
'headers': {
|
113
|
+
'Content-Type': 'application/json; charset=UTF-8',
|
114
|
+
"Authorization": "Bearer " + LINE_ACCESS_TOKEN
|
115
|
+
},
|
116
|
+
'method': 'get'
|
117
|
+
})
|
118
|
+
.getContent();
|
119
|
+
const lineImageBlob = Utilities.base64Encode(lineImageResponse);
|
120
|
+
const API_KEY = ${API_KEY};
|
121
|
+
const visionRequestUrl = 'https://vision.googleapis.com/v1/images:annotate?key=' + API_KEY;
|
122
|
+
const payload = JSON.stringify({
|
123
|
+
"requests":[
|
124
|
+
{
|
125
|
+
"image": {
|
126
|
+
"content": lineImageBlob
|
127
|
+
},
|
128
|
+
"features": [
|
129
|
+
{
|
130
|
+
"type": "TEXT_DETECTION",
|
131
|
+
"maxResults": 1
|
132
|
+
}
|
133
|
+
]
|
134
|
+
}
|
135
|
+
]
|
136
|
+
});
|
137
|
+
const visionTextResponse = UrlFetchApp.fetch(visionRequestUrl, {
|
138
|
+
method: "POST",
|
139
|
+
contentType: "application/json",
|
140
|
+
payload: payload,
|
141
|
+
})
|
142
|
+
.getContentText();
|
143
|
+
const visionTextJson = JSON.parse(visionTextResponse);
|
144
|
+
const visionText = visionTextJson.responses[0].fullTextAnnotation.
|
145
|
+
text;
|
146
|
+
const messages = [
|
147
|
+
{
|
148
|
+
"type":"text",
|
149
|
+
"text": visionText
|
150
|
+
}
|
151
|
+
]
|
152
|
+
UrlFetchApp.fetch("https://api.line.me/v2/bot/message/reply", {
|
153
|
+
"headers": {
|
154
|
+
"Content-Type": "application/json; charset=UTF-8",
|
155
|
+
"Authorization": "Bearer " + LINE_ACCESS_TOKEN,
|
156
|
+
},
|
157
|
+
"method": "post",
|
158
|
+
"payload": JSON.stringify({
|
159
|
+
"replyToken": replyToken,
|
160
|
+
"messages": messages,
|
161
|
+
})
|
162
|
+
});
|
163
|
+
}
|
164
|
+
```
|
9
画像削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -90,7 +90,6 @@
|
|
90
90
|
TypeError: undefined からプロパティ「postData」を読み取れません。(行 3、ファイル「コード」)
|
91
91
|
```
|
92
92
|
とエラーが出てきます。
|
93
|
-

|
94
93
|
|
95
94
|
**試みたこと**
|
96
95
|
・${API_KEY}は与えられたものに変更した。(""を付けて)
|
8
画像追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -90,6 +90,7 @@
|
|
90
90
|
TypeError: undefined からプロパティ「postData」を読み取れません。(行 3、ファイル「コード」)
|
91
91
|
```
|
92
92
|
とエラーが出てきます。
|
93
|
+

|
93
94
|
|
94
95
|
**試みたこと**
|
95
96
|
・${API_KEY}は与えられたものに変更した。(""を付けて)
|
7
画像追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -40,6 +40,7 @@
|
|
40
40
|
```
|
41
41
|
上記のコードで
|
42
42
|
文字起こし君で文字起こしをするサンプルです。と表示されるのですが
|
43
|
+

|
43
44
|
```ここに言語を入力
|
44
45
|
function doPost(e) {
|
45
46
|
const lineJson = JSON.parse(e.postDate.contents);
|
6
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"requests":[
|
16
16
|
{
|
17
17
|
"image": {
|
18
|
-
"content":
|
18
|
+
"content": imageBlob
|
19
19
|
},
|
20
20
|
"features": [
|
21
21
|
{
|
@@ -60,7 +60,7 @@
|
|
60
60
|
"requests":[
|
61
61
|
{
|
62
62
|
"image": {
|
63
|
-
"content":
|
63
|
+
"content": imageBlob
|
64
64
|
},
|
65
65
|
"features": [
|
66
66
|
{
|
5
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
const imageResponse = UrlFetchApp.fetch(url, {
|
5
5
|
'headers': {
|
6
6
|
'Content-Type': 'application/json; charset=UTF-8',
|
7
|
-
"Authorization": "Bearer " + LINE_ACCESS_TOKEN
|
8
7
|
},
|
9
8
|
'method': 'get'
|
10
9
|
})
|
@@ -50,7 +49,6 @@
|
|
50
49
|
const imageResponse = UrlFetchApp.fetch(url, {
|
51
50
|
'headers': {
|
52
51
|
'Content-Type': 'application/json; charset=UTF-8',
|
53
|
-
"Authorization": "Bearer " + LINE_ACCESS_TOKEN
|
54
52
|
},
|
55
53
|
'method': 'get'
|
56
54
|
})
|
4
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
```ここに言語を入力
|
2
2
|
function doPost(e) {
|
3
|
-
const LINE_ACCESS_TOKEN = ${ACCESS_TOKEN};
|
4
|
-
const lineJson = JSON.parse(e.postData.contents);
|
5
|
-
const replyToken = lineJson.events[0].replyToken;
|
6
|
-
const messageId = lineJson.events[0].message.id;
|
7
|
-
const
|
3
|
+
const url = "https://dividable.net/wp/wp-content/uploads/2019/01/sample2.png";
|
8
|
-
const
|
4
|
+
const imageResponse = UrlFetchApp.fetch(url, {
|
9
5
|
'headers': {
|
10
6
|
'Content-Type': 'application/json; charset=UTF-8',
|
11
7
|
"Authorization": "Bearer " + LINE_ACCESS_TOKEN
|
@@ -13,7 +9,7 @@
|
|
13
9
|
'method': 'get'
|
14
10
|
})
|
15
11
|
.getContent();
|
16
|
-
const
|
12
|
+
const imageBlob = Utilities.base64Encode(imageResponse);
|
17
13
|
const API_KEY = ${API_KEY};
|
18
14
|
const visionRequestUrl = 'https://vision.googleapis.com/v1/images:annotate?key=' + API_KEY;
|
19
15
|
const payload = JSON.stringify({
|
@@ -40,32 +36,64 @@
|
|
40
36
|
const visionTextJson = JSON.parse(visionTextResponse);
|
41
37
|
const visionText = visionTextJson.responses[0].fullTextAnnotation.
|
42
38
|
text;
|
43
|
-
const messages = [
|
44
|
-
{
|
45
|
-
"type":"text",
|
46
|
-
|
39
|
+
console.log(visionText);
|
47
|
-
|
40
|
+
}
|
48
|
-
|
41
|
+
```
|
42
|
+
上記のコードで
|
43
|
+
文字起こし君で文字起こしをするサンプルです。と表示されるのですが
|
44
|
+
```ここに言語を入力
|
45
|
+
function doPost(e) {
|
46
|
+
const lineJson = JSON.parse(e.postDate.contents);
|
47
|
+
console.log(lineJson);
|
48
|
+
/**
|
49
|
-
|
49
|
+
const url = "https://dividable.net/wp/wp-content/uploads/2019/01/sample2.png";
|
50
|
+
const imageResponse = UrlFetchApp.fetch(url, {
|
50
|
-
|
51
|
+
'headers': {
|
51
|
-
|
52
|
+
'Content-Type': 'application/json; charset=UTF-8',
|
52
|
-
|
53
|
+
"Authorization": "Bearer " + LINE_ACCESS_TOKEN
|
53
54
|
},
|
54
|
-
|
55
|
+
'method': 'get'
|
55
|
-
"payload": JSON.stringify({
|
56
|
-
"replyToken": replyToken,
|
57
|
-
"messages": messages,
|
58
56
|
})
|
57
|
+
.getContent();
|
58
|
+
const imageBlob = Utilities.base64Encode(imageResponse);
|
59
|
+
const API_KEY = ${API_KEY};
|
60
|
+
const visionRequestUrl = 'https://vision.googleapis.com/v1/images:annotate?key=' + API_KEY;
|
61
|
+
const payload = JSON.stringify({
|
62
|
+
"requests":[
|
63
|
+
{
|
64
|
+
"image": {
|
65
|
+
"content": lineImageBlob
|
66
|
+
},
|
67
|
+
"features": [
|
68
|
+
{
|
69
|
+
"type": "TEXT_DETECTION",
|
70
|
+
"maxResults": 1
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
]
|
59
75
|
});
|
76
|
+
const visionTextResponse = UrlFetchApp.fetch(visionRequestUrl, {
|
77
|
+
method: "POST",
|
78
|
+
contentType: "application/json",
|
79
|
+
payload: payload,
|
80
|
+
})
|
81
|
+
.getContentText();
|
82
|
+
const visionTextJson = JSON.parse(visionTextResponse);
|
83
|
+
const visionText = visionTextJson.responses[0].fullTextAnnotation.
|
84
|
+
text;
|
85
|
+
console.log(visionText);
|
86
|
+
**/
|
60
87
|
}
|
61
88
|
```
|
62
|
-
|
89
|
+
にすると
|
63
90
|
```ここに言語を入力
|
64
91
|
TypeError: undefined からプロパティ「postData」を読み取れません。(行 3、ファイル「コード」)
|
65
92
|
```
|
93
|
+
とエラーが出てきます。
|
66
94
|
|
67
95
|
**試みたこと**
|
68
|
-
・${
|
96
|
+
・${API_KEY}は与えられたものに変更した。(""を付けて)
|
69
97
|
・Googleの拡張サービスのDrive APIを有効にした。
|
70
98
|
・LINE BOTをGASで作成(https://qiita.com/t_gata/items/897936761695124ef920)を参照した。
|
71
99
|
|
3
インデントの調整
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,56 +6,56 @@
|
|
6
6
|
const messageId = lineJson.events[0].message.id;
|
7
7
|
const lineImageUrl = "https://api.line.me/v2/bot/message/" + messageId + "/content/";
|
8
8
|
const lineImageResponse = UrlFetchApp.fetch(lineImageUrl, {
|
9
|
-
|
9
|
+
'headers': {
|
10
|
-
|
10
|
+
'Content-Type': 'application/json; charset=UTF-8',
|
11
|
-
|
11
|
+
"Authorization": "Bearer " + LINE_ACCESS_TOKEN
|
12
|
-
|
12
|
+
},
|
13
|
-
|
13
|
+
'method': 'get'
|
14
|
-
|
14
|
+
})
|
15
|
-
|
15
|
+
.getContent();
|
16
16
|
const lineImageBlob = Utilities.base64Encode(lineImageResponse);
|
17
17
|
const API_KEY = ${API_KEY};
|
18
18
|
const visionRequestUrl = 'https://vision.googleapis.com/v1/images:annotate?key=' + API_KEY;
|
19
19
|
const payload = JSON.stringify({
|
20
|
-
|
20
|
+
"requests":[
|
21
|
-
|
21
|
+
{
|
22
|
-
|
22
|
+
"image": {
|
23
|
-
|
23
|
+
"content": lineImageBlob
|
24
|
-
|
24
|
+
},
|
25
|
-
|
25
|
+
"features": [
|
26
|
-
|
26
|
+
{
|
27
|
-
|
27
|
+
"type": "TEXT_DETECTION",
|
28
|
-
|
28
|
+
"maxResults": 1
|
29
|
-
|
29
|
+
}
|
30
|
-
|
30
|
+
]
|
31
|
-
|
31
|
+
}
|
32
|
-
|
32
|
+
]
|
33
33
|
});
|
34
34
|
const visionTextResponse = UrlFetchApp.fetch(visionRequestUrl, {
|
35
|
-
|
35
|
+
method: "POST",
|
36
|
-
|
36
|
+
contentType: "application/json",
|
37
|
-
|
37
|
+
payload: payload,
|
38
38
|
})
|
39
39
|
.getContentText();
|
40
40
|
const visionTextJson = JSON.parse(visionTextResponse);
|
41
41
|
const visionText = visionTextJson.responses[0].fullTextAnnotation.
|
42
42
|
text;
|
43
43
|
const messages = [
|
44
|
-
|
44
|
+
{
|
45
|
-
|
45
|
+
"type":"text",
|
46
|
-
|
46
|
+
"text": visionText
|
47
|
-
|
47
|
+
}
|
48
48
|
]
|
49
49
|
UrlFetchApp.fetch("https://api.line.me/v2/bot/message/reply", {
|
50
|
-
|
50
|
+
"headers": {
|
51
|
-
|
51
|
+
"Content-Type": "application/json; charset=UTF-8",
|
52
|
-
|
52
|
+
"Authorization": "Bearer " + LINE_ACCESS_TOKEN,
|
53
|
-
|
53
|
+
},
|
54
|
-
|
54
|
+
"method": "post",
|
55
|
-
|
55
|
+
"payload": JSON.stringify({
|
56
|
-
|
56
|
+
"replyToken": replyToken,
|
57
|
-
|
57
|
+
"messages": messages,
|
58
|
-
|
58
|
+
})
|
59
59
|
});
|
60
60
|
}
|
61
61
|
```
|
2
試みたことの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -65,6 +65,7 @@
|
|
65
65
|
```
|
66
66
|
|
67
67
|
**試みたこと**
|
68
|
+
・${ACCESS_TOKEN}と${API_KEY}は与えられたものに変更した。(""を付けて)
|
68
69
|
・Googleの拡張サービスのDrive APIを有効にした。
|
69
70
|
・LINE BOTをGASで作成(https://qiita.com/t_gata/items/897936761695124ef920)を参照した。
|
70
71
|
|
1
補足情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -59,11 +59,14 @@
|
|
59
59
|
});
|
60
60
|
}
|
61
61
|
```
|
62
|
-
エラー内容
|
62
|
+
**エラー内容**
|
63
63
|
```ここに言語を入力
|
64
64
|
TypeError: undefined からプロパティ「postData」を読み取れません。(行 3、ファイル「コード」)
|
65
65
|
```
|
66
66
|
|
67
|
-
試みたこと
|
67
|
+
**試みたこと**
|
68
68
|
・Googleの拡張サービスのDrive APIを有効にした。
|
69
|
-
・LINE BOTをGASで作成(https://qiita.com/t_gata/items/897936761695124ef920)を参照した。
|
69
|
+
・LINE BOTをGASで作成(https://qiita.com/t_gata/items/897936761695124ef920)を参照した。
|
70
|
+
|
71
|
+
**補足情報**
|
72
|
+
使用書籍:独学プログラマーのためのAIアプリ開発がわかる本
|