LoginSignup
0
0

More than 1 year has passed since last update.

Slack API 使用時のtoken送信メソッドはPOSTを使う

Last updated at Posted at 2021-05-18

tokenの送信メソッドはPOSTのみに

トークン(xox...)はPOSTじゃなきゃダメになったらしい。
Three major deprecations you may be impacted by beginning February 24, 2021

// これじゃダメ(仕変前に作ったものであればOK)
$url = "https://slack.com/api/chat.postMessage?token=${token}&channel=${channel}&text=${text}";
file_get_contents($url);
// OK
$url = "https://slack.com/api/chat.postMessage?channel=${channel}&text=${text}";
$body = 'token='.$token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_URL,$url);
$result = curl_exec($ch);
curl_close($ch);

今回新規でSlack Botの開発案件があったんですが、前作ったBotのソースコピペでトークンだけ変えればいけるだろうと思ってたところ、この仕変に気付かず小1時間ハマりました…そもそもクレデンシャルをGet送信するなというのとちゃんとドキュメント読めという話ではありますが;
公式のテストツールもGetで投げてるのでtoken指定だとエラーになります。
https://api.slack.com/methods/chat.postMessage/test

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0