0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP: Zoom の token を取得

Posted at

次のページを参考にしました。
JWT With Zoom
Zoomのアプリケーションの作成

gen_token.php
# ! /usr/bin/php
<?php
// ------------------------------------------------------------------
//	gen_token.php
//
//					Mar/13/2021
//
// ------------------------------------------------------------------
function file_write_proc ($string_out,$file_out)
{
	try
		{
		$fp_out=fopen ($file_out,"w");
		fputs ($fp_out,$string_out);
		fclose ($fp_out);
		}
	catch (Exception $ee)
		{
		print("*** error *** file_write_proc ***\n");
		print('Error:'.$ee->getMessage());
		}
}

// ------------------------------------------------------------------
function urlsafe_base64_encode($str){
	return str_replace(array('+','/','='), array('-','_',''), base64_encode($str));
}

// ------------------------------------------------------------------
$API_Key = '*******';
$API_Secret = '********************************';
$expiration = time() + 3600;

$header = urlsafe_base64_encode('{"alg":"HS256","typ":"JWT"}');
$payload = urlsafe_base64_encode('{"iss":"'.$API_Key.'","exp":'.$expiration.'}');
$signature = urlsafe_base64_encode(hash_hmac('sha256', "$header.$payload", $API_Secret, TRUE));
$token = "$header.$payload.$signature";


$unit_aa = array ();
$unit_aa['token'] = $token;

$str_json = json_encode ($unit_aa);

$file_out = "token.json";
file_write_proc ($str_json,$file_out);

// ------------------------------------------------------------------
?>

実行すると次のファイルが作成されます。

token.json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6I1234567890123****NjE1NjM1NTgxfQ.TjM67nGJrtyHJfuaVIlCTOoo"
}

次のようなスクリプトで使えます。

token=`jq .token token.json | sed 's/"//g'`
http "https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1" \
    "Authorization:Bearer ${token}"

関連ページ
Zoom API の使い方

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?