SlackAPPに登録する
-
Tokenと権限を付与
メニューから OAuth & Permissions を選択
OAuth Access Tokenを確認する
下部のScopesから権限を付与
今回はチャンネルリスト取得なので下記権限
Access user’s public channels
channels:history
Access information about user’s public channels
channels:read
chat:write:bot
- APIを確認する
channels.list method | Slack
Method URL: https://slack.com/api/channels.list
Preferred HTTP method: GET
Accepted content types: application/x-www-form-urlencoded
Argument Example Required Description
token xxxx-xxxxxxxxx-xxxx Required
Authentication token bearing required scopes.
データを取得する
- Jsonで取得(Ruby)
require 'net/http'
require 'uri'
require "json"
require 'pp'
res = Net::HTTP.get(URI.parse('https://slack.com/api/channels.list?token=xxxx-xxxxxxxxx-xxxx'))
hash = JSON.parse(res)
channels = hash["channels"]
channels.map { |channel| puts "##{channel["name"]}" }