forked from jolicode/slack-php-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretrieve-users.php
32 lines (25 loc) · 978 Bytes
/
retrieve-users.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
use JoliCode\Slack\Api\Model\ObjsUser;
use JoliCode\Slack\ClientFactory;
use JoliCode\Slack\Exception\SlackErrorResponse;
require_once __DIR__.'/../../vendor/autoload.php';
$client = ClientFactory::create('Your token');
/** @var ObjsUser[] $users */
$users = [];
$cursor = '';
try {
do {
// This method requires your token to have the scope "users:read"
$response = $client->usersList([
'limit' => 200,
'cursor' => $cursor,
]);
$users = array_merge($users, $response->getMembers());
$cursor = $response->getResponseMetadata() ? $response->getResponseMetadata()->getNextCursor() : '';
} while (!empty($cursor));
echo sprintf('Here is the names of the members of your workspace: %s', implode(', ', array_map(function(ObjsUser $user) {
return $user->getName();
}, $users)));
} catch (SlackErrorResponse $e) {
echo 'Fail to retrieve the members.', PHP_EOL, $e->getMessage();
}