PHP Invalid Access Token

So I’m using the below code to firstly get an access token…

$clientID="";
$clientSecret="
";
$content = “grant_type=client_credentials&client_id=$clientID&client_secret=$clientSecret”;
$token_url=“https://zoom.us/oauth/token”;

$ch = curl_init($token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$objJSON = json_decode($result,false);

Which works fine and I get a token back…

$webinarID = “164712960”;
$token_url=“https://api.zoom.us/v2/webinars/”. $webinarID . “/registrants”;
$content ="";
$headers = array(
‘authorization’ => 'Bearer ’ . $objJSON->access_token,
‘content-type’ => ‘application/json’
);

$ch = curl_init($token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);

However with the above that I am using to register a new attendee (aware I am not passing any content yet) I am getting a {“code”:124,“message”:“Invalid access token.”} response back.

What am I doing wrong?

Hey @TCADeveloper,

Please try passing in a request body (content) and see if that fixes the issue.

Thanks,
Tommy

Hi Tommy,

I’m now passing it the following JSON, and its still returning Invalid.

{“email":"simon@simonhix.co.uk”,“first_name”:“Simon”,“last_name”:“Hix”,“address”:“dsfhkdjsfh st”,“city”:“jackson heights”,“country”:“US”,“zip”:“11371”,“state”:“NY”,“phone”:“00000000”,“industry”:“Food”,“org”:“Cooking Org”,“job_title”:“Cooking Org”,“purchasing_time_frame”:“1-3 months”,“role_in_purchase_process”:“Influencer”,“no_of_employees”:“10”,“comments”:“Looking forward to the Webinar”,“custom_questions”:{“title”:“What do you hope to learn from this Webinar?”,“value”:“Look forward to learning how you come up with new recipes and what other services you offer.”}}

Simon

Hey @TCADeveloper,

Thanks, can you private message me your access token so I can take a look?

Thanks,
Tommy

I am have similar problem with almost same code but I get “Invalid api key or secret.”
Any idea what could cause this?

Hey @stanislav.furman,

Which API are you calling?

Thanks,
Tommy

Hi @tommy
I am trying to implement a webform to add participants to a webinar.
So, I am first trying to obtain an authorization token by calling https://zoom.us/oauth/token? just like in the original message of this topic. Then I try to add participants:
https://api.zoom.us/v2/webinars/{webinar_id}/registrants
… but I get {“code”:200,“message”:“Invalid api key or secret.”}.

I guess the token that I receive at my step 1 is not meant to be used to communicate with webinars methods.

I looked the OAuth authorization steps but I am not sure how step 1 can be implemented in my PHP code. It seems like I need to redirect the user to authorization page every time?

Hey @stanislav.furman,

It sounds like you want to use JWT Token auth instead of OAuth since you aren’t needing to call the API on external Zoom users behalf.

Thanks,
Tommy