質問編集履歴
4
md調整
test
CHANGED
File without changes
|
test
CHANGED
@@ -242,7 +242,7 @@
|
|
242
242
|
|
243
243
|
?>
|
244
244
|
|
245
|
-
|
245
|
+
```
|
246
246
|
|
247
247
|
|
248
248
|
|
@@ -256,7 +256,7 @@
|
|
256
256
|
|
257
257
|
|
258
258
|
|
259
|
-
```
|
259
|
+
```
|
260
260
|
|
261
261
|
$ curl -v -X POST https://api.line.me/v2/bot/message/push \
|
262
262
|
|
@@ -290,9 +290,9 @@
|
|
290
290
|
|
291
291
|
}'
|
292
292
|
|
293
|
-
|
294
|
-
|
295
|
-
```
|
293
|
+
```
|
294
|
+
|
295
|
+
|
296
296
|
|
297
297
|
### エラー内容
|
298
298
|
|
3
シェルで試した内容を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -242,4 +242,98 @@
|
|
242
242
|
|
243
243
|
?>
|
244
244
|
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
## ターミナルから直接送信する
|
250
|
+
|
251
|
+
プログラムではなく、シェルで直接呼び出せるか確認しましたが、結果送信できませんでした。
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
```sh
|
260
|
+
|
261
|
+
$ curl -v -X POST https://api.line.me/v2/bot/message/push \
|
262
|
+
|
263
|
+
-H 'Content-Type:application/json' \
|
264
|
+
|
265
|
+
-H 'Authorization: Bearer <チャンネルのアクセストークン>' \
|
266
|
+
|
267
|
+
-d '{
|
268
|
+
|
269
|
+
"to": "<送り先のユーザーID>",
|
270
|
+
|
271
|
+
"messages":{
|
272
|
+
|
273
|
+
{
|
274
|
+
|
275
|
+
"type": "text",
|
276
|
+
|
277
|
+
"text": "Hello, world1"
|
278
|
+
|
279
|
+
},
|
280
|
+
|
281
|
+
{
|
282
|
+
|
283
|
+
"type":"text",
|
284
|
+
|
285
|
+
"text":"Hello, world2"
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
}'
|
292
|
+
|
293
|
+
|
294
|
+
|
245
|
-
```
|
295
|
+
```
|
296
|
+
|
297
|
+
### エラー内容
|
298
|
+
|
299
|
+
400版エラーで、```Could not read the request body```が返ってきており、
|
300
|
+
|
301
|
+
エラー文からは、本文が読み込めない形式になっているといった内容になっています。
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
```
|
306
|
+
|
307
|
+
< HTTP/1.1 400 Bad Request
|
308
|
+
|
309
|
+
< Server: nginx
|
310
|
+
|
311
|
+
< Date: Sun, 05 May 2019 08:03:56 GMT
|
312
|
+
|
313
|
+
< Content-Type: application/json;charset=UTF-8
|
314
|
+
|
315
|
+
< Transfer-Encoding: chunked
|
316
|
+
|
317
|
+
< Connection: keep-alive
|
318
|
+
|
319
|
+
< x-line-request-id: xxx
|
320
|
+
|
321
|
+
< x-content-type-options: nosniff
|
322
|
+
|
323
|
+
< x-xss-protection: 1; mode=block
|
324
|
+
|
325
|
+
< cache-control: no-cache, no-store, max-age=0, must-revalidate
|
326
|
+
|
327
|
+
< pragma: no-cache
|
328
|
+
|
329
|
+
< expires: 0
|
330
|
+
|
331
|
+
< x-frame-options: DENY
|
332
|
+
|
333
|
+
<
|
334
|
+
|
335
|
+
* Connection #0 to host api.line.me left intact
|
336
|
+
|
337
|
+
{"message":"Could not read the request body"}
|
338
|
+
|
339
|
+
```
|
2
URL調整
test
CHANGED
File without changes
|
test
CHANGED
@@ -156,7 +156,7 @@
|
|
156
156
|
|
157
157
|
|
158
158
|
|
159
|
-
https://github.com/line/line-bot-sdk-php
|
159
|
+
[https://github.com/line/line-bot-sdk-php](https://github.com/line/line-bot-sdk-php)
|
160
160
|
|
161
161
|
|
162
162
|
|
1
他の方法も記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -145,3 +145,101 @@
|
|
145
145
|
?>
|
146
146
|
|
147
147
|
```
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
## LINEが提供しているライブラリを使った場合
|
152
|
+
|
153
|
+
下記のライブラリを使って検証してみましたが、同じ様なエラーで動きませんでした。
|
154
|
+
|
155
|
+
おそらく、根本的な部分に問題があるのだとは思います。
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
https://github.com/line/line-bot-sdk-php
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
### エラー内容
|
164
|
+
|
165
|
+
```
|
166
|
+
|
167
|
+
object(LINE\LINEBot\Response)#6 (3) { ["httpStatus":"LINE\LINEBot\Response":private]=> int(415) ["body":"LINE\LINEBot\Response":private]=> string(56) "{"message":"The content type, 'null', is not supported"}" ["headers":"LINE\LINEBot\Response":private]=> array(13) { ["Server"]=> string(5) "nginx" ["Date"]=> string(29) "Sat, 04 May 2019 11:09:23 GMT" ["Content-Type"]=> string(30) "application/json;charset=UTF-8" ["Transfer-Encoding"]=> string(7) "chunked" ["Connection"]=> string(10) "keep-alive" ["x-line-request-id"]=> string(36) "***" ["x-content-type-options"]=> string(7) "nosniff" ["x-xss-protection"]=> string(13) "1; mode=block" ["cache-control"]=> string(46) "no-cache, no-store, max-age=0, must-revalidate" ["pragma"]=> string(8) "no-cache" ["expires"]=> string(1) "0" ["x-frame-options"]=> string(4) "DENY" ["accept"]=> string(16) "application/json" } }
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
### ソース
|
174
|
+
|
175
|
+
```php
|
176
|
+
|
177
|
+
<?php
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
require_once "vendor/autoload.php";
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
const LINEACCESSTOKEN = 'LINEのアクセストークン';
|
186
|
+
|
187
|
+
const LINESECRETTOKEN = 'LINEのシークレットトークン';
|
188
|
+
|
189
|
+
const SAMPLEUSERID = '送信するユーザーID';
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
// コール
|
194
|
+
|
195
|
+
// ポスト値を取得
|
196
|
+
|
197
|
+
$postTo = SAMPLEUSERID;
|
198
|
+
|
199
|
+
$message = "test";
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
pushLineMessage($message, $postTo);
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
// LINEでメッセージを送信する
|
208
|
+
|
209
|
+
function pushLineMessage($pushMessage, $to) {
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
// botを作成
|
214
|
+
|
215
|
+
$httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient(LINEACCESSTOKEN);
|
216
|
+
|
217
|
+
$bot = new \LINE\LINEBot($httpClient, [
|
218
|
+
|
219
|
+
'channelSecret' => LINESECRETTOKEN
|
220
|
+
|
221
|
+
]);
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
// メッセージを作成
|
226
|
+
|
227
|
+
$textMessageBuilder = new \LINE\LINEBot\MessageBuilder\TextMessageBuilder($pushMessage);
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
// メール送信
|
232
|
+
|
233
|
+
$response = $bot->pushMessage($to, $textMessageBuilder);
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
var_dump($response);
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
?>
|
244
|
+
|
245
|
+
```
|