Created
September 2, 2021 20:26
-
-
Save angrychimp/381f2a3d5dab072fc1d581ab03c81b11 to your computer and use it in GitHub Desktop.
Fetch number of members in a Slack channel
This file contains 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
<?php | |
// Your ID and token | |
$botToken = 'xoxb-xxxxxxxxxx-xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx'; | |
$channelID = 'C12345678'; | |
// Setup cURL | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => "https://slack.com/api/conversations.info?channel=$channelID&include_num_members=true", | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 0, | |
CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_CUSTOMREQUEST => 'GET', | |
CURLOPT_HTTPHEADER => array( | |
'Content-Type: application/x-www-form-urlencoded', | |
"Authorization: Bearer $botToken" | |
), | |
)); | |
$response = curl_exec($curl); | |
$responseData = json_decode($response, TRUE); | |
curl_close($curl); | |
echo $responseData['num_members']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment