Last active
January 29, 2021 15:41
-
-
Save balvinder294/d8819dd85d5dd47ac0294f6e04b37c71 to your computer and use it in GitHub Desktop.
Method to get scheduled meeting list in Java using Zoom Rest Api for Zoom Meetings - https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetings | By https://tekraze.com
This file contains 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
import io.jsonwebtoken.Jwts; | |
import io.jsonwebtoken.SignatureAlgorithm; | |
import io.jsonwebtoken.security.Keys; | |
/** | |
* Request to list all meetings by userId/email of the user | |
* | |
* @param userIdOrEmail optional userId/email value | |
* | |
* @param meetingType scheduled/live/upcoming | |
* | |
* @return zoomMeetingsListResponseDTO the dto containing list of meetings | |
*/ | |
@Override | |
public ZoomMeetingsListResponseDTO listMeetings(Optional<String> userIdOrEmail, Optional<String> meetingType) { | |
log.debug("Request to list all Zoom meetings by User id or email {}", userIdOrEmail); | |
// replace me with user id in case, listing meetings for a different user than admin | |
String listMeetingUrl = "https://api.zoom.us/v2/users/me/meetings"; | |
// replace either user Id or email here with your user id/email | |
if(userIdOrEmail.isPresent()) { | |
listMeetingUrl = "https://api.zoom.us/v2/users/"+ userIdOrEmail.get() +"/meetings"; | |
} | |
RestTemplate restTemplate = new RestTemplate(); | |
HttpHeaders headers = new HttpHeaders(); | |
headers.add("Authorization", "Bearer " + generateZoomJWTTOken()); | |
headers.add("content-type", "application/json"); | |
HttpEntity<?> requestEntity = new HttpEntity<>(headers); | |
UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpUrl(listMeetingUrl); | |
if(meetingType.isPresent()) { | |
urlBuilder.queryParam("type", meetingType.get()); | |
} | |
ResponseEntity<ZoomMeetingsListResponseDTO> response = restTemplate | |
.exchange(urlBuilder.toUriString(), HttpMethod.GET, requestEntity, ZoomMeetingsListResponseDTO.class); | |
if(response.getStatusCodeValue() == 200) { | |
return response.getBody(); | |
} else if (response.getStatusCodeValue() == 404) { | |
throw new InternalServerException("User id or email not found for supplied value"); | |
} | |
return null; | |
} | |
/** | |
* Generate JWT token for Zoom using api credentials | |
* | |
* @return JWT Token String | |
*/ | |
private String generateZoomJWTTOken() { | |
String id = UUID.randomUUID().toString().replace("-", ""); | |
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; | |
Date creation = new Date(System.currentTimeMillis()); | |
Date tokenExpiry = new Date(System.currentTimeMillis() + (1000 * 60)); | |
Key key = Keys | |
.hmacShaKeyFor(zoomApiSecret.getBytes()); | |
return Jwts.builder() | |
.setId(id) | |
.setIssuer(zoomApiKey) | |
.setIssuedAt(creation) | |
.setSubject("") | |
.setExpiration(tokenExpiry) | |
.signWith(key, signatureAlgorithm) | |
.compact(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment