├── .gitignore ├── README.md ├── composer.json ├── composer.lock └── src ├── Zoom.php └── ZoomException.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zoom PHP API 2 | 3 | A simple PHP wrapper for the Zoom API 4 | 5 | [](https://packagist.org/packages/espresso-dev/zoom-php) 6 | [](https://packagist.org/packages/espresso-dev/zoom-php) 7 | [](https://packagist.org/packages/espresso-dev/zoom-php) 8 | 9 | > [Composer](#installation) package available. 10 | 11 | ## Requirements 12 | 13 | - PHP 7 or higher 14 | - cURL 15 | - Zoom Developer Account 16 | - Zoom App 17 | 18 | ## Get started 19 | 20 | To use the [Zoom API](https://marketplace.zoom.us/docs/guides/tools-resources/zoom-apis), you will need to register a Zoom app. Follow the [Create an OAuth App guide](https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app). 21 | 22 | ### Installation 23 | 24 | I strongly advice using [Composer](https://getcomposer.org) to keep updates as smooth as possible. 25 | 26 | ``` 27 | $ composer require espresso-dev/zoom-php 28 | ``` 29 | 30 | ### Initialize the class 31 | 32 | ```php 33 | use EspressoDev\Zoom\Zoom; 34 | 35 | $zoom = new Zoom([ 36 | 'appId' => 'YOUR_APP_ID', 37 | 'appSecret' => 'YOUR_APP_SECRET', 38 | 'redirectUri' => 'YOUR_APP_REDIRECT_URI' 39 | ]); 40 | 41 | echo "Login with Zoom"; 42 | ``` 43 | 44 | ### Authenticate user (OAuth2) 45 | 46 | ```php 47 | // Get the OAuth callback code 48 | $code = $_GET['code']; 49 | 50 | // Get the access token (valid for 1 hour) and refresh token 51 | $token = $zoom->getOAuthToken($code); 52 | 53 | echo 'Your token is: ' . $token->access_token; 54 | echo 'Your refresh token is: ' . $token->refresh_token; 55 | ``` 56 | 57 | ### Get users scheduled meetings 58 | 59 | ```php 60 | // Set user access token 61 | $zoom->setAccessToken($token); 62 | 63 | // Get the users scheduled meetins 64 | $meetings = $zoom->getUserMeetings('me', 'scheduled'); 65 | 66 | echo '
'; 67 | print_r($meetings); 68 | echo ''; 69 | ``` 70 | 71 | **All methods return the API data as `json_decode()` - so you can directly access the data.** 72 | 73 | ## Available methods 74 | 75 | ### Setup Zoom 76 | 77 | `new Zoom(/ );` 78 | 79 | `array` if you want to perform oAuth: 80 | 81 | ```php 82 | new Zoom([ 83 | 'appId' => 'YOUR_APP_ID', 84 | 'appSecret' => 'YOUR_APP_SECRET', 85 | 'redirectUri' => 'YOUR_APP_REDIRECT_URI' 86 | ]); 87 | ``` 88 | 89 | `string` once you have a token and just want to return *read-only* data: 90 | 91 | ```php 92 | new Zoom('ACCESS_TOKEN'); 93 | ``` 94 | 95 | ### Get login URL 96 | 97 | `getLoginUrl( )` 98 | 99 | ```php 100 | getLoginUrl( 101 | 'state' 102 | ); 103 | ``` 104 | 105 | ### Get OAuth token (Short lived valid for 1 hour) 106 | 107 | `getOAuthToken($code)` 108 | 109 | ### Refresh access token for another 1 hour and get updated refresh token 110 | 111 | `refreshToken($refreshToken)` 112 | 113 | ### Set / Get access token 114 | 115 | - Set the access token, for further method calls: `setAccessToken($token)` 116 | - Get the access token, if you want to store it for later usage: `getAccessToken()` 117 | 118 | ### User methods 119 | 120 | See [Zoom API Documentation](https://marketplace.zoom.us/docs/api-reference/zoom-api) for more information about each method. 121 | 122 | **Authenticated methods** 123 | 124 | - `getUserMeetings(<$id>, <$type>, <$page_size>, <$page_number>)` 125 | - `getUserMeetings(<$id>, <$page_size>, <$page_number>)` 126 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "espresso-dev/zoom-php", 3 | "description": "A simple PHP class for accessing the Zoom API", 4 | "keywords": ["zoom", "api"], 5 | "homepage": "https://github.com/espresso-dev/zoom-php", 6 | "type": "library", 7 | "require": { 8 | "php": ">=7", 9 | "ext-curl": "*" 10 | }, 11 | "autoload": { 12 | "psr-4": { 13 | "EspressoDev\\Zoom\\": "src/" 14 | } 15 | }, 16 | "license": "MIT", 17 | "authors": [ 18 | { 19 | "name": "Herman Schutte", 20 | "email": "herman@espresso.dev" 21 | } 22 | ], 23 | "minimum-stability": "dev" 24 | } 25 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "ec3fe06da235782abc7491c7284a7a19", 8 | "packages": [], 9 | "packages-dev": [], 10 | "aliases": [], 11 | "minimum-stability": "dev", 12 | "stability-flags": [], 13 | "prefer-stable": false, 14 | "prefer-lowest": false, 15 | "platform": { 16 | "php": ">=7", 17 | "ext-curl": "*" 18 | }, 19 | "platform-dev": [] 20 | } 21 | -------------------------------------------------------------------------------- /src/Zoom.php: -------------------------------------------------------------------------------- 1 | setAppId($config['appId']); 31 | $this->setAppSecret($config['appSecret']); 32 | $this->setRedirectUri($config['redirectUri']); 33 | 34 | if (isset($config['timeout'])) { 35 | $this->setTimeout($config['timeout']); 36 | } 37 | 38 | if (isset($config['connectTimeout'])) { 39 | $this->setConnectTimeout($config['connectTimeout']); 40 | } 41 | } elseif (is_string($config)) { 42 | // For read-only 43 | $this->setAccessToken($config); 44 | } else { 45 | throw new ZoomException('Error: __construct() - Configuration data is missing.'); 46 | } 47 | } 48 | 49 | public function getLoginUrl($state = '') 50 | { 51 | return self::API_OAUTH_URL . '?client_id=' . $this->getAppId() . '&redirect_uri=' . urlencode($this->getRedirectUri()) . 52 | '&response_type=code' . ($state != '' ? '&state=' . $state : ''); 53 | 54 | throw new ZoomException("Error: getLoginUrl()"); 55 | } 56 | 57 | public function getUserMeetings($id, $type = 'live', $page_size = 30, $page_number = 1) 58 | { 59 | return $this->_makeCall('users/' . $id . '/meetings', compact('type', 'page_size', 'page_number')); 60 | } 61 | 62 | public function getUserWebinars($id, $page_size = 30, $page_number = 1) 63 | { 64 | return $this->_makeCall('users/' . $id . '/webinars', compact('page_size', 'page_number')); 65 | } 66 | 67 | public function getOAuthToken($code) 68 | { 69 | $apiData = array( 70 | 'grant_type' => 'authorization_code', 71 | 'redirect_uri' => $this->getRedirectUri(), 72 | 'code' => $code 73 | ); 74 | 75 | $authorization = base64_encode($this->getAppId() . ':' . $this->getAppSecret()); 76 | $header = ['Authorization: Basic ' . $authorization]; 77 | 78 | $result = $this->_makeOAuthCall(self::API_OAUTH_TOKEN_URL, $apiData, 'POST', $header); 79 | 80 | return $result; 81 | } 82 | 83 | public function refreshToken($refreshToken) 84 | { 85 | $apiData = array( 86 | 'grant_type' => 'refresh_token', 87 | 'refresh_token' => $refreshToken 88 | ); 89 | 90 | $authorization = base64_encode($this->getAppId() . ':' . $this->getAppSecret()); 91 | $header = ['Authorization: Basic ' . $authorization]; 92 | 93 | $result = $this->_makeOAuthCall(self::API_OAUTH_TOKEN_URL, $apiData, 'POST', $header); 94 | 95 | return $result; 96 | } 97 | 98 | protected function _makeCall($function, $params = null, $method = 'GET') 99 | { 100 | if (!isset($this->_accesstoken)) { 101 | throw new ZoomException("Error: _makeCall() | $function - This method requires an authenticated users access token."); 102 | } 103 | 104 | $paramString = null; 105 | 106 | if (isset($params) && is_array($params)) { 107 | $paramString = '?' . http_build_query($params); 108 | } 109 | 110 | $apiCall = self::API_URL . $function . (('GET' === $method) ? $paramString : null); 111 | 112 | $headerData = [ 113 | 'Authorization: Bearer ' . $this->getAccessToken()->access_token, 114 | 'Accept: application/json' 115 | ]; 116 | 117 | $ch = curl_init(); 118 | curl_setopt($ch, CURLOPT_URL, $apiCall); 119 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headerData); 120 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->_connectTimeout); 121 | curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->_timeout); 122 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 123 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 124 | curl_setopt($ch, CURLOPT_HEADER, true); 125 | 126 | $jsonData = curl_exec($ch); 127 | 128 | if (!$jsonData) { 129 | throw new ZoomException('Error: _makeCall() - cURL error: ' . curl_error($ch), curl_errno($ch)); 130 | } 131 | 132 | list($headerContent, $jsonData) = explode("\r\n\r\n", $jsonData, 2); 133 | 134 | curl_close($ch); 135 | 136 | return json_decode($jsonData); 137 | } 138 | 139 | private function _makeOAuthCall($apiHost, $params, $method = 'POST', $header = []) 140 | { 141 | $paramString = null; 142 | 143 | if (isset($params) && is_array($params)) { 144 | $paramString = '?' . http_build_query($params); 145 | } 146 | 147 | $apiCall = $apiHost . (('GET' === $method) ? $paramString : null); 148 | 149 | $ch = curl_init(); 150 | curl_setopt($ch, CURLOPT_URL, $apiCall); 151 | curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($header, ['Accept: application/json'])); 152 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 153 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 154 | curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->_timeout); 155 | 156 | if ($method === 'POST') { 157 | curl_setopt($ch, CURLOPT_POST, count($params)); 158 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); 159 | } 160 | 161 | $jsonData = curl_exec($ch); 162 | 163 | if (!$jsonData) { 164 | throw new ZoomException('Error: _makeOAuthCall() - cURL error: ' . curl_error($ch)); 165 | } 166 | 167 | curl_close($ch); 168 | 169 | return json_decode($jsonData); 170 | } 171 | 172 | public function setAccessToken($token) 173 | { 174 | $this->_accesstoken = $token; 175 | } 176 | 177 | public function getAccessToken() 178 | { 179 | return $this->_accesstoken; 180 | } 181 | 182 | public function setAppId($appId) 183 | { 184 | $this->_appId = $appId; 185 | } 186 | 187 | public function getAppId() 188 | { 189 | return $this->_appId; 190 | } 191 | 192 | public function setAppSecret($appSecret) 193 | { 194 | $this->_appSecret = $appSecret; 195 | } 196 | 197 | public function getAppSecret() 198 | { 199 | return $this->_appSecret; 200 | } 201 | 202 | public function setRedirectUri($redirectUri) 203 | { 204 | $this->_redirectUri = $redirectUri; 205 | } 206 | 207 | public function getRedirectUri() 208 | { 209 | return $this->_redirectUri; 210 | } 211 | 212 | public function setTimeout($timeout) 213 | { 214 | $this->_timeout = $timeout; 215 | } 216 | 217 | public function setConnectTimeout($connectTimeout) 218 | { 219 | $this->_connectTimeout = $connectTimeout; 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /src/ZoomException.php: -------------------------------------------------------------------------------- 1 |