Created
October 10, 2021 19:51
-
-
Save stevesohcot/24c96d4056826f62bda16f34db6215ea to your computer and use it in GitHub Desktop.
PHP Ring Central 2 Legged Auth Login
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
| <?php | |
| require "vendor/autoload.php"; | |
| $rcsdk = new RingCentral\SDK\SDK(constant('RINGCENTRAL_TWO_LEG_CLIENT_ID'), constant('RINGCENTRAL_TWO_LEG_CLIENT_SECRET'), constant('RINGCENTRAL_TWO_LEG_SERVER_URL'), constant('RINGCENTRAL_TWO_LEG_APP_NAME') ); | |
| $platform = $rcsdk->platform(); | |
| $platform->login(constant('RINGCENTRAL_TWO_LEG_USERNAME'), constant('RINGCENTRAL_TWO_LEG_EXT'), constant('RINGCENTRAL_TWO_LEG_PASSWORD')); | |
| // This example API endpoint will get all users in Ring Central | |
| // After retrieving the data, I'm putting everything into an array | |
| $endpoint = '/account/~/extension'; | |
| $queryParams = array(); | |
| $queryParams['perPage'] = 999; | |
| $data = ringCentralGetRequest($platform, $endpoint, $queryParams); | |
| $records = $data->records; | |
| $arrPeople = []; | |
| foreach ($records as $record) { | |
| $arrPeople[$record->id] = $record->name; | |
| } | |
| foreach ($arrPeople as $key => $value) { | |
| // $key = Ring Central ID | |
| // $value = username | |
| print "<br> $key - $value"; | |
| } | |
| function ringCentralGetRequest($platform, $endpoint, $params) { | |
| try { | |
| $resp = $platform->get($endpoint, $params); | |
| #echo "<p>".$resp->text()."</p>"; | |
| return $resp->json(); | |
| } catch (\RingCentral\SDK\Http\ApiException $e) { | |
| print 'Expected HTTP Error: ' . $e->getMessage() . PHP_EOL; | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment