Accessing Zoom Meeting Data Using Zoom API in PHP
- First, you need to acquire your API credentials after creating an app within the Zoom App Marketplace. Specifically, the Client ID and Client Secret for OAuth apps or API Key and API Secret for JWT apps.
- To interact with the Zoom API, you need an access token. If you are using JWT, you generate it using the API Key and Secret. For OAuth, initial authorization using Authorization Code flow is needed to obtain an access token.
- Here is an example code snippet for obtaining a JWT token and using it to authenticate API requests:
$apiKey = 'YOUR_API_KEY';
$apiSecret = 'YOUR_API_SECRET';
$payload = array(
"iss" => $apiKey,
"exp" => time() + 3600
);
$jwt = JWT::encode($payload, $apiSecret);
// Use the JWT token to make API requests
function getZoomData($jwt) {
$url = "https://api.zoom.us/v2/users/me/meetings";
$headers = array(
"Authorization: Bearer $jwt",
"Content-Type: application/json"
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response);
}
$meetings = getZoomData($jwt);
print_r($meetings);
- For OAuth apps, you'll initially redirect users to Zoom's authorization URL to authorize your app and then handle the redirect back to your server by exchanging the authorization code for an access token.
- Once you have the access token, subsequent API requests can be made similarly using the `'Authorization: Bearer {access_token}'` header. Adjust the endpoint and method according to the Zoom API documentation specific to your needs, such as retrieving meeting details, participant lists, etc.
- The Zoom meeting data is accessible from various endpoints. An example request to list past meetings of a user looks like this:
function listPastMeetings($accessToken, $userId) {
$url = "https://api.zoom.us/v2/users/$userId/meetings?page_number=1&page_size=30&type=past";
$headers = array(
"Authorization: Bearer $accessToken",
"Content-Type: application/json"
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$pastMeetings = listPastMeetings($accessToken, 'me');
print_r($pastMeetings);
- Ensure error handling is implemented to catch common HTTP errors or specific Zoom API error codes, to assist in managing requests and debugging potential issues.
- Remember to comply with Zoom API rate limits by implementing mechanisms to handle the `429 Too Many Requests` error, such as robust retry logic with exponential backoff.