0

I updated the access token and refresh tokens and latest tokens but still get the response as "{"code":124,"message":"Invalid access token."}" I am following the oauth process create zoom meeting function:

public function create_zoom_meeting($meeting_details) {
    $res = false;
    if(!empty($meeting_details)) {
        $post_fields = [
            "topic"=> !empty($meeting_details['topic']) ? $meeting_details['topic'] : "",
            "type"=> "2",
            "start_time"=> $meeting_details['start_time'],
            "duration" => $meeting_details['duration'],
            "timezone" => !empty($meeting_details['time_zone']) ? $meeting_details['time_zone'] :"Asia/Kolkata",
            "settings" => [
                "host_video"=> "true",
                "participant_video"=> "false",
                "join_before_host"=> "true",
                "jbh_time" => "5",
                "registration_type" => "0",
                "auto_recording" => "none",
                "meeting_authentication" => "true"
                ]
        ];
        $headers = [
            "Content-Type : application/json",
            "authorization : Bearer {$this->access_token}",
            "Host: zoom.us"
            ];
        $res = $this->post_curl_request('https://api.zoom.us/v2/users/me/meetings', json_encode($post_fields), $headers);
    }
    var_dump($res);
    return $res;
}

my curl request

private function post_curl_request($url, $post_body = [], $headers = []) {
    var_dump($post_body, $headers);
    $curl = curl_init();
    $curl_opt_array = array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 30,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_POST => 1,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_POSTFIELDS => $post_body
    );
    curl_setopt_array($curl,$curl_opt_array);
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}

how can I fix this issue

  • I hope you have followed steps from https://marketplace.zoom.us/docs/guides/auth/jwt#key-secret to generate JWT access token – OMi Shah Jul 07 '21 at 05:07
  • no I am following oauth2.0 process – Lakmuthudcl Jul 07 '21 at 05:09
  • @Lakmuthudcl you'll need to post your code on how you are generating the `access_token`. Most likely hitting the `https://zoom.us/oauth/token` endpoint. – Gibron Jun 08 '22 at 01:02
  • Also reducing your attempt to a cURL would make it easier to debug where the issue is. Eg. `curl -X POST -H "Authorization: Basic [base64(clientid:clientsecret)]" -H "Content-Type: application/x-www-form-urlencoded" "https://zoom.us/oauth/token?grant_type=authorization_code&code=[access_code]&redirect_uri=[redirect_uri]"` – Gibron Jun 08 '22 at 01:04

1 Answers1

0

If you want to use with JWT then you can do this like in your class:

private $zoom_api_key = 'YOUR_API_KEY';
private $zoom_api_secret = 'YOUR_API_SECRET_KEY';

//function to generate JWT
private function generateJWTKey() {
    $key = $this->zoom_api_key;
    $secret = $this->zoom_api_secret;
    $token = array(
        "iss" => $key,
        "exp" => time() + 3600 //60 seconds as suggested
    );
    return JWT::encode( $token, $secret );
}

//function to send request
protected function sendRequest($data)
{
//Enter_Your_Email
$request_url = "https://api.zoom.us/v2/users/{user_email}/meetings";

$headers = array(
    "authorization: Bearer ".$this->generateJWTKey(),
    "content-type: application/json",
    "Accept: application/json",
);

    $postFields = json_encode($data);

        $ch = curl_init();
        curl_setopt_array($ch, array(
        CURLOPT_URL => $request_url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => $postFields,
        CURLOPT_HTTPHEADER => $headers,
        ));

        $response = curl_exec($ch);
        $err = curl_error($ch);
        curl_close($ch);
        if (!$response) {
                return $err;
    }
    return json_decode($response);
}
Mahmud Hasan Jion
  • 445
  • 1
  • 5
  • 14