p.gallo
(Pierpaolo)
March 24, 2023, 11:16am
1
I’m migrating from JWT to oauth so I created Server-to-Server OAuth app with credentilas and scopes.
Initially no problems but during the last days I had an issue with oauth token.
With these credentials I create tokens in php
$url = 'https://zoom.us/oauth/token';
$data = array(
'grant_type' => 'client_credentials'
);
$headers = array(
'Authorization: Basic '. base64_encode(my_Client_ID:my_Client_secret)
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if(curl_errno($curl)) {
echo 'Curl error: ' . curl_error($curl);
}
curl_close($curl);
$data0=json_decode($response, true);
With this token I call some APIs, for example
$url = "https://api.zoom.us/v2/past_meetings/{$meeting_id}/participants";
$curl = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer {$access_token}"
));
$response = curl_exec($curl);
or
$url = "https://api.zoom.us/oauth/check_token?access_token={$access_token}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
if (isset($data->error)) {
print_r($data->error);
}
The error I get is invalid_request .
I tried also creating a new token with shell but it’s the same.
I tried also with different client ID and secret ID always the same error.
Any ideas?
Can you help me, please?
Thanks
p.gallo
(Pierpaolo)
March 28, 2023, 1:33pm
2
Am I the only one experiencing this problem?
@p.gallo ,
Thank you for posting in the Zoom Developer Forum. Can you share screenshot of the message you are seeing ?
p.gallo
(Pierpaolo)
April 20, 2023, 10:30am
4
Pierpaolo:
print_r($data->error);
Hi
there’s no specific screenshot: the print_r($data->error)
line prints out invalid_request
print_r($data); prints
stdClass Object
(
[reason] => Internal Error
[error] => invalid_request
)
Below the code I use for creating and check the token
<?php
$url = 'https://zoom.us/oauth/token';
$data = array(
'grant_type' => 'client_credentials'
);
$headers = array(
'Authorization: Basic '. base64_encode('*my_Client_ID*:*my_Client_secret*')
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if(curl_errno($curl)) {
echo 'Curl error: ' . curl_error($curl);
}
curl_close($curl);
echo "<pre>";
print_r($response);
echo "</pre>";
$data0=json_decode($response, true);
$timestamp = time() + 3460;
$expiration = date('YmdHi', $timestamp);
$data0['creazione'] = date('YmdHi', time());
$data0['expiration'] = $expiration;
$generated_token=$data0['access_token'];
echo "<pre>";
print_r($data0);
echo "</pre>";
$generated_token=$data0['access_token'];
echo "<pre>";
print_r($generated_token);
echo "</pre>";
$url = "https://api.zoom.us/oauth/check_token?access_token={$generated_token}";
echo "<pre>";
print_r($url);
echo "</pre>";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
if (isset($data->error)) {
echo "Invalid or expired token.\n";
echo "<h3>";
print_r($data->error);
echo "<pre>";
print_r($data);
echo "</pre></h3>";
} else {
echo "Valid token.\n";
}
?>
Is there something else I can share with you?
Thanks
Pierpaolo
Ran into this just this week as we swap over to OAuth.
Your query string needs the following:
grant_type = “account_credentials”
account_id = “{Account Id in the OAuth App}”
You get an access token that lives for 1 hour, with no refresh token. When you need a new token, you call the endpoint again to fetch a new token.
Server-to-Server OAuth (zoom.us)
p.gallo
(Pierpaolo)
April 20, 2023, 11:40am
6
Thank you
I’m pretty sure I still miss something because also with accout credentials I got the same error (altough the token is created)
Below the code
<?php
$url = 'https://zoom.us/oauth/token';
$data = array(
'grant_type' => 'account_credentials',
'account_id' => '*myAccount_id*'
);
$headers = array(
'Authorization: Basic '. base64_encode('*my_Client_ID*:*my_Client_secret*')
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if(curl_errno($curl)) {
echo 'Curl error: ' . curl_error($curl);
}
curl_close($curl);
echo "<pre>";
print_r($response);
echo "</pre>";
$data0=json_decode($response, true);
$timestamp = time() + 3460;
$expiration = date('YmdHi', $timestamp);
$data0['creazione'] = date('YmdHi', time());
$data0['expiration'] = $expiration;
$generated_token=$data0['access_token'];
echo "<pre>";
print_r($data0);
echo "</pre>";
$generated_token=$data0['access_token'];
echo "<pre>";
print_r($generated_token);
echo "</pre>";
$url = "https://api.zoom.us/oauth/check_token?access_token={$generated_token}";
echo "<pre>";
print_r($url);
echo "</pre>";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
if (isset($data->error)) {
echo "Invalid or expired token.\n";
echo "<h3>";
print_r($data->error);
echo "<pre>";
print_r($data);
echo "</pre></h3>";
} else {
echo "Valid token.\n";
}
?>
Thanks again
system
(system)
Closed
April 23, 2024, 3:17am
7
This topic was automatically closed 368 days after the last reply. New replies are no longer allowed.