Last active
September 16, 2021 15:18
-
-
Save haimingzhao/9016b34364722bd1f0124d6cb2835ea0 to your computer and use it in GitHub Desktop.
Get more than 100 usernames from a slack channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
SLACK_API_TOKEN='' # Your token here | |
FROM_CHANNEL_ID='' # Get the id from the bottom of the channel description | |
NEW_CHANNEL_ID='' | |
LIMIT=200 # default limit was 100 need to change based on size | |
members = requests.get('https://slack.com/api/conversations.members?token=%s&channel=%s&limit=%s' % (SLACK_API_TOKEN, FROM_CHANNEL_ID, LIMIT)).json()['members'] | |
existing_members = requests.get('https://slack.com/api/conversations.members?token=%s&channel=%s&limit=%s' % (SLACK_API_TOKEN, NEW_CHANNEL_ID, LIMIT)).json()['members'] | |
for id in members: | |
if id not in existing_members: | |
# print(id) | |
user = requests.get('https://slack.com/api/users.info?token=%s&user=%s' % (SLACK_API_TOKEN, id)).json() | |
if user['ok']: | |
print('@' + user['user']['name']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment