LoginSignup
9

More than 5 years have passed since last update.

slackのアップロード用APIをpythonから叩いて画像アップロード

Last updated at Posted at 2015-03-03

前提
アクセストークンは手動、もしくはmechanize等を利用して取得済みとする。
通信ライブラリはrequestsを使用する

with open("FILE_PATH",'rb') as f:
    param = {'token':access_token, 'channels':CHANNEL_ID,'title':'タイトル'}
    r = requests.post("https://slack.com/api/files.upload", params=param,files={'file':f})

CHANNEL_IDは各チャンネルのタイトルクリックしてAdd a servive integration... に飛ぶとURLパラメータにidがあるのでそれを利用する。

参考 https://github.com/os/slacker/blob/master/slacker/__init__.py

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
9