teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

md調整

2019/05/05 08:46

投稿

hasshy
hasshy

スコア102

title CHANGED
File without changes
body CHANGED
@@ -120,14 +120,14 @@
120
120
  }
121
121
 
122
122
  ?>
123
+ ```
123
124
 
124
-
125
125
  ## ターミナルから直接送信する
126
126
  プログラムではなく、シェルで直接呼び出せるか確認しましたが、結果送信できませんでした。
127
127
 
128
128
 
129
129
 
130
- ```sh
130
+ ```
131
131
  $ curl -v -X POST https://api.line.me/v2/bot/message/push \
132
132
  -H 'Content-Type:application/json' \
133
133
  -H 'Authorization: Bearer <チャンネルのアクセストークン>' \
@@ -144,8 +144,8 @@
144
144
  }
145
145
  }
146
146
  }'
147
+ ```
147
148
 
148
- ```
149
149
  ### エラー内容
150
150
  400版エラーで、```Could not read the request body```が返ってきており、
151
151
  エラー文からは、本文が読み込めない形式になっているといった内容になっています。

3

シェルで試した内容を追加

2019/05/05 08:46

投稿

hasshy
hasshy

スコア102

title CHANGED
File without changes
body CHANGED
@@ -120,4 +120,51 @@
120
120
  }
121
121
 
122
122
  ?>
123
+
124
+
125
+ ## ターミナルから直接送信する
126
+ プログラムではなく、シェルで直接呼び出せるか確認しましたが、結果送信できませんでした。
127
+
128
+
129
+
130
+ ```sh
131
+ $ curl -v -X POST https://api.line.me/v2/bot/message/push \
132
+ -H 'Content-Type:application/json' \
133
+ -H 'Authorization: Bearer <チャンネルのアクセストークン>' \
134
+ -d '{
135
+ "to": "<送り先のユーザーID>",
136
+ "messages":{
137
+ {
138
+ "type": "text",
139
+ "text": "Hello, world1"
140
+ },
141
+ {
142
+ "type":"text",
143
+ "text":"Hello, world2"
144
+ }
145
+ }
146
+ }'
147
+
148
+ ```
149
+ ### エラー内容
150
+ 400版エラーで、```Could not read the request body```が返ってきており、
151
+ エラー文からは、本文が読み込めない形式になっているといった内容になっています。
152
+
153
+ ```
154
+ < HTTP/1.1 400 Bad Request
155
+ < Server: nginx
156
+ < Date: Sun, 05 May 2019 08:03:56 GMT
157
+ < Content-Type: application/json;charset=UTF-8
158
+ < Transfer-Encoding: chunked
159
+ < Connection: keep-alive
160
+ < x-line-request-id: xxx
161
+ < x-content-type-options: nosniff
162
+ < x-xss-protection: 1; mode=block
163
+ < cache-control: no-cache, no-store, max-age=0, must-revalidate
164
+ < pragma: no-cache
165
+ < expires: 0
166
+ < x-frame-options: DENY
167
+ <
168
+ * Connection #0 to host api.line.me left intact
169
+ {"message":"Could not read the request body"}
123
170
  ```

2

URL調整

2019/05/05 08:45

投稿

hasshy
hasshy

スコア102

title CHANGED
File without changes
body CHANGED
@@ -77,7 +77,7 @@
77
77
  下記のライブラリを使って検証してみましたが、同じ様なエラーで動きませんでした。
78
78
  おそらく、根本的な部分に問題があるのだとは思います。
79
79
 
80
- https://github.com/line/line-bot-sdk-php
80
+ [https://github.com/line/line-bot-sdk-php](https://github.com/line/line-bot-sdk-php)
81
81
 
82
82
  ### エラー内容
83
83
  ```

1

他の方法も記載

2019/05/04 11:18

投稿

hasshy
hasshy

スコア102

title CHANGED
File without changes
body CHANGED
@@ -71,4 +71,53 @@
71
71
  }
72
72
 
73
73
  ?>
74
+ ```
75
+
76
+ ## LINEが提供しているライブラリを使った場合
77
+ 下記のライブラリを使って検証してみましたが、同じ様なエラーで動きませんでした。
78
+ おそらく、根本的な部分に問題があるのだとは思います。
79
+
80
+ https://github.com/line/line-bot-sdk-php
81
+
82
+ ### エラー内容
83
+ ```
84
+ 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" } }
85
+ ```
86
+
87
+ ### ソース
88
+ ```php
89
+ <?php
90
+
91
+ require_once "vendor/autoload.php";
92
+
93
+ const LINEACCESSTOKEN = 'LINEのアクセストークン';
94
+ const LINESECRETTOKEN = 'LINEのシークレットトークン';
95
+ const SAMPLEUSERID = '送信するユーザーID';
96
+
97
+ // コール
98
+ // ポスト値を取得
99
+ $postTo = SAMPLEUSERID;
100
+ $message = "test";
101
+
102
+ pushLineMessage($message, $postTo);
103
+
104
+ // LINEでメッセージを送信する
105
+ function pushLineMessage($pushMessage, $to) {
106
+
107
+ // botを作成
108
+ $httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient(LINEACCESSTOKEN);
109
+ $bot = new \LINE\LINEBot($httpClient, [
110
+ 'channelSecret' => LINESECRETTOKEN
111
+ ]);
112
+
113
+ // メッセージを作成
114
+ $textMessageBuilder = new \LINE\LINEBot\MessageBuilder\TextMessageBuilder($pushMessage);
115
+
116
+ // メール送信
117
+ $response = $bot->pushMessage($to, $textMessageBuilder);
118
+
119
+ var_dump($response);
120
+ }
121
+
122
+ ?>
74
123
  ```