
PHPによるZoom APIの実装例(第2回(全4回))
第2回:Zoomミーティング参加者の取得
前回は、Server-to-Server OAuthによる認証、ZoomのユーザーIDの取得を行いました。
今回Zoomミーティングの参加者の一覧を表示するAPIを試していきます。
Server-to-Server OAuth認証については、前回説明していますので
今回の説明はそれ以降のAPIの説明となります。
ただし、そもそもZoomミーティングの参加者はAPIを使わなくとも
Zoomにサインインして、レポート→使用状況レポート→用途
のページで見れるものですので、あまりAPIを使用する機会はないのかもしれません。


今回のAPIの使用例では、
Zoomにサインインしてレポートで見た上記画像で表示されているとおり、
ミーティング参加者の氏名・メールを取得するというものになります。
使用するAPIは公式のZoomAPIリファレンスにある
Get past meeting participants
になります。
https://developers.zoom.us/docs/meeting-sdk/apis/#operation/pastMeetingParticipants
GET /past_meetings/{meetingId}/participants
{meetingId}は、Zoom会議のID(11桁の数字)です。
出席者を調べたいZoom会議のIDを指定して、出席者を取得するAPIになります。
まずはhtml部分の画面イメージです。
テキストボックス内に、ZoomIDを入力して取得ボタンをクリックすると
下のテーブル箇所に出席者の氏名が入る仕組みです。
APIで取得できる値はいくつかあるのですが、
ここでは簡単に「name」と「user_email」のみにしています。

<h5>Zoom会議参加者リスト</h5>
<form id="sanka" name="sanka" method="post" action="">
<div>
<label>ZoomID</label>
<input type="text" name="zoomid" ime-mode-disable value="<?php
echo htmlspecialchars($zoomid, ENT_QUOTES, 'UTF-8');?>"/>
<div><input type="submit" class="btn btn-primary" value="取得" /></div>
</div>
</form>
<hr />
<table>
<thead>
<tr>
<th>氏名</th>
<th>Mail</th>
</tr>
</thead>
続いて、「name」と「user_email」に値を入れるPHP部分の説明です。
// 参加者リストの取得
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.zoom.us/v2/past_meetings/' . $zoomid . '/participants?page_size=300',
CURLOPT_HTTPHEADER => array(
'authorization: Bearer ' . $token,
'content-type: application/json'
),
CURLOPT_RETURNTRANSFER => true
));
$response = curl_exec($curl);
$err = curl_error($curl);
$json = json_decode($response, true);
CURLOPT_URL => 'https://api.zoom.us/v2/past_meetings/' . $zoomid . '/participants?page_size=300',
この$zoomidが、フォームで入力したZoomIDになります。これをAPIのURL文字列として渡します。
$tokenは、第1回で取得した認証トークンになります。
実際に取得してみると下記のように出力されました。

ただし、これだといつのミーティングのことなのかわかりませんので、一緒の画面にZoomミーティングの情報も出してみようと思います。画面イメージは下記の通りです。

Zoomミーティングの情報を取得するためには、Zoomミーティング参加者を取得するAPIとは別に取得する必要があります。
使用するAPIは公式のZoomAPIリファレンスにある
Get past meeting details
になります。
https://developers.zoom.us/docs/meeting-sdk/apis/#operation/pastMeetingDetails
GET /past_meetings/{meetingId}
先ほどの参加者を取得するAPIから、/participantsがなくなったものがURLとなります。下記のようにアクセスします。
// ミーティング情報の取得
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.zoom.us/v2/past_meetings/' . $zoomid,
CURLOPT_HTTPHEADER => array(
'authorization: Bearer ' . $token,
'content-type: application/json'
),
CURLOPT_RETURNTRANSFER => true
));
$response = curl_exec($curl);
$err = curl_error($curl);
$json2 = json_decode($response, true);
curl_close($curl);
それでは、画面(3)を出力するためのhtml部とPHPのコードです。
この記事が気に入ったらチップで応援してみませんか?