6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SlackApiでチャンネルリストを取得する

Posted at

SlackAPPに登録する

  1. Appを作成
    Slack API: Applications | Slack

  2. 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
  1. 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"]}" }
6
4
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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?