Skip to content

Instantly share code, notes, and snippets.

@angrychimp
Created September 2, 2021 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angrychimp/381f2a3d5dab072fc1d581ab03c81b11 to your computer and use it in GitHub Desktop.
Save angrychimp/381f2a3d5dab072fc1d581ab03c81b11 to your computer and use it in GitHub Desktop.
Fetch number of members in a Slack channel
<?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