Created
November 2, 2017 19:49
-
-
Save joshuawoodward/be56b3c455a05fd8475d25ebb68498d9 to your computer and use it in GitHub Desktop.
Find users that haven't logged in
This file contains hidden or 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
<?php | |
$api_key = ''; | |
$api_secret = ''; | |
date_default_timezone_set('America/Los_Angeles'); | |
$users = get_users(); | |
echo "Found ". count($users) . " users\r\n"; | |
$threshold = time() - (90 * 24 * 60 * 60); //90 days ago | |
$count = 0; | |
foreach($users as $user) { | |
$lastLogin = strtotime($user->lastLoginTime); | |
if($lastLogin < $threshold && $user->type != 1){ | |
echo $user->id . " - " . $user->email . " - " . $user->first_name . " " . $user->last_name . " - " . $user->lastLoginTime . "\r\n"; | |
//calling the below function will downgrade users to basic | |
//downgrade_user($user->id); | |
$count++; | |
} | |
} | |
echo "Found " . $count . " non-basic users who haven't logged in within the threshold \r\n"; | |
function get_users () { | |
global $api_key, $api_secret; | |
$url = 'https://api.zoom.us/v1/user/list'; | |
$params = array( | |
"api_key" => $api_key, | |
"api_secret" => $api_secret, | |
"page_size" => 10000 | |
); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec ($ch); | |
$response = json_decode($response); | |
return $response->users; | |
} | |
function downgrade_user ($user_id) { | |
global $api_key, $api_secret; | |
$url = 'https://api.zoom.us/v1/user/update'; | |
$params = array( | |
"api_key" => $api_key, | |
"api_secret" => $api_secret, | |
"id" => $user_id, | |
"type" => 1 | |
); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); | |
curl_exec ($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment