How to get an access token using Python 3.7

Description
The text may be weird because I am using Google Translate, but thank you.

I want to get an access token from OAuth this time using AWS Lambda and Python 3.7.

Which App Type (OAuth / Chatbot / JWT / Webhook)?
OAuth

How To Reproduce (If applicable)
I cannot use JWT because I am using my company Zoom account. So I want to implement it with OAuth.
The PHP code and test request below worked fine, but I don’t know how to get it in Python.

<?php
session_start();
$Client_ID = '"xxxxxxxxx"';
$Client_Secret = 'xxxxxx';
$Redirect_URL ='xxxxxx';
if(isset($_GET['code'])){
	$basic = base64_encode($Client_ID.':'.$Client_Secret);
	$curl = curl_init();
	curl_setopt_array($curl, array(
		CURLOPT_URL => "https://zoom.us/oauth/token?grant_type=authorization_code&code={$_GET['code']}&redirect_uri=$Redirect_URL",
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => "",
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => "POST",
		CURLOPT_HTTPHEADER => array(
			"authorization: Basic $basic"
		),
	));
	$response = curl_exec($curl);
	$err = curl_error($curl);
	curl_close($curl);
	if ($err) {
		echo "cURL Error #:" . $err;
	} else {
		echo $response;
	}
}else{
	echo 'Authorization Error';
}
?>

Hey @kurono

Thanks for posting on the Zoom Devforum! I am still learning, but I will try my best to help answer your question. :slightly_smiling_face:

Checkout this related thread that may have the answer you are looking for:

If this thread did not help, please let us know by replying back here and someone from the Developer Relations team will get back to you shortly.

Thanks,
DeveloperBot

Thanks for suggesting the solution!
But it didn’t work.

First of all, how do I get the authorization code using Python?

Hey @kurono,

Have you had a chance to check out our OAuth Guide’s “Getting an Access Token” section yet?

Step 1 in this guide only needs to be done once. After you install/authorize the OAuth app, you’ll use the auth code in the url to request an access token (in any language—our APIs are platform/language agnostic).

It’s not until Step 2 in this guide where your Python code would start. It would use the access_token (which lasts one hour) returned in step 1. Once it expires, you need to use the latest refresh_token to get a new access_token. So keep in mind that you’ll need to store this access_token/refresh_token each time a new one is requested/refreshed.

After these steps, you can use your up to date access_token to hit any API endpoint of interest. When it comes to hitting a particular API endpoint, you can retrieve the code snippet in your language of choice from the embedded Postman tool in our API documentation. But to be clear, we do not have an end-to-end sample app, in Python, for our entire OAuth flow at this time.

I hope this helps to clarify!

Best,
Will

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.