@tidai510

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Slack APIのconversations.listを使用してチャンネル一覧を取得したい

Q&A

Closed

Slack APIのconversations.listを使用してチャンネル一覧を取得したい

GASでSlackのチャンネル一覧を取得するプログラムを作成しています。
conversations.listを実行すると、エラーが発生しました。
解決方法を教えて頂きたいです。
宜しくお願い致します。

発生している問題・エラー

useSlackApiGet()の戻り値でエラーinvalid_authが返ってくる

該当するソースコード

function myFunction() {
  channelsList();
}

/* チャンネルリストを取得 */
function channelsList() {
  var method = 'conversations.list';
  var params = '&types=public_channel,private_channel';
  var list = useSlackApiGet(method, params);
  //ここでエラー
  //list.ok:false
  //list.error:invalid_auth
  if (list.ok) {

  }
}

/* Slack APIを実行(GET) */
function useSlackApiGet(methodUrl, data) {
  var token = PropertiesService.getScriptProperties().getProperty("SLACK_ACCESS_TOKEN");
  var apiUrl = 'https://slack.com/api/';
  var params = '?token='+token+data;
  var url = apiUrl + methodUrl + params;
  var res = UrlFetchApp.fetch(apiUrl + methodUrl + params);
  return list = JSON.parse(res.getContentText());
}
### 自分で試したこと
https://api.slack.com/methods/conversations.list/test
ここで上記ソースと同じtokenを使用してみた所、チャンネルの一覧は取得できました。

0 likes

1Answer

Comments

  1. @tidai510

    Questioner

    ヘッダーに渡してみた所、取得することができました。
    ありがとうございます。

Your answer might help someone💌