Created
October 10, 2021 19:55
-
-
Save stevesohcot/2d9c3653b07369740241f20b28e4c687 to your computer and use it in GitHub Desktop.
PHP Ring Central 3 Legged Auth Login - 1 of 2
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'); | |
| use RingCentral\SDK\Http\HttpException; | |
| use RingCentral\SDK\Http\ApiResponse; | |
| use RingCentral\SDK\SDK; | |
| $rcsdk = new SDK(constant('RINGCENTRAL_CLIENT_ID'), constant('RINGCENTRAL_CLIENT_SECRET'), constant('RINGCENTRAL_SERVER_URL')); | |
| $platform = $rcsdk->platform(); | |
| // Using the authUrl to call the platform function | |
| $url = $platform->authUrl(array( | |
| 'redirectUri' => constant('RINGCENTRAL_REDIRECT_URL'), // something like "engine.php?oauth2callback" | |
| 'state' => 'initialState', | |
| 'brandId' => '', | |
| 'display' => '', | |
| 'prompt' => '' | |
| )); | |
| function ringCentralCallGetRequest($endpoint, $params){ | |
| global $platform; | |
| try { | |
| $resp = $platform->get($endpoint, $params); | |
| #echo "<p>".$resp->text()."</p>"; | |
| return $resp->text(); | |
| } catch (\RingCentral\SDK\Http\ApiException $e) { | |
| print 'Expected HTTP Error: ' . $e->getMessage() . PHP_EOL; | |
| } | |
| } | |
| ?> | |
| <?php if (!isset($_SESSION['ringCentralSessionAccessToken'])) { ?> | |
| <a href="<?php echo $url; ?>">Login RingCentral Account</a> | |
| <?php | |
| } else { | |
| $platform->auth()->setData((array)$_SESSION['ringCentralSessionAccessToken']); | |
| if (!$platform->loggedIn()) { | |
| ?> | |
| <p>Invalid login, please try again:</p> | |
| <a href="<?php echo $url; ?>">Login RingCentral Account</a> | |
| <?php | |
| } else { | |
| ?> | |
| <h1>Ring Central Call Logs</h1> | |
| <?php | |
| $queryParams = array(); | |
| $queryParams['perPage'] = 999; | |
| $endpoint = "/restapi/v1.0/account/~/call-log"; | |
| $data = json_decode( ringCentralCallGetRequest($endpoint, $queryParams) ); | |
| print "<pre>"; | |
| print_r( $data); | |
| print "</pre>"; | |
| $records = $data->records; | |
| if (count($records) == 0) { | |
| print "No data available"; | |
| } else { | |
| // print / loop through the data | |
| } | |
| } // logged in | |
| } // session set | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment