Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(CkPython) Zoom API - Create JWT to Authenticate API RequestsSee more Zoom ExamplesCreates a JWT for the Zoom API. For more information, see https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#using-jwt
import sys import chilkat # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. # Use your API key and secret here... apiKey = "o9rw6Gq0RnqlkfaSqtCMOA" apiSecret = "UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR" # Create a JWT to authenticate Zoom API requests. jwt = chilkat.CkJwt() jose = chilkat.CkJsonObject() success = jose.UpdateString("alg","HS256") success = jose.UpdateString("typ","JWT") # Build claims to look like this: # {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363} claims = chilkat.CkJsonObject() success = claims.UpdateString("iss",apiKey) success = claims.UpdateNull("aud") # Set the timestamp of when the JWT was created to now. curDateTime = jwt.GenNumericDate(0) success = claims.AddIntAt(-1,"iat",curDateTime) # Set the timestamp defining an expiration time (end time) for the token # to be now + 1 month(3600 * 24 * 30 seconds) oneMonth = 3600 * 24 * 30 success = claims.AddIntAt(-1,"exp",curDateTime + oneMonth) # Produce the smallest possible JWT: jwt.put_AutoCompact(True) strJwt = jwt.createJwt(jose.emit(),claims.emit(),apiSecret) print(strJwt) # Let's test the JWT to by sending the following request: # curl --request GET \ # --url 'https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1' \ # --header 'authorization: Bearer { your_token }' \ # --header 'content-type: application/json http = chilkat.CkHttp() # Implements the following CURL command: # curl --request GET \ # --url 'https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1' \ # --header 'authorization: Bearer { your_token }' \ # --header 'content-type: application/json # Use the following online tool to generate HTTP code from a CURL command # Convert a cURL Command to HTTP Source Code http.SetRequestHeader("content-type","application/json") # Adds the "Authorization: Bearer { your_token }" header. http.put_AuthToken(strJwt) sbResponseBody = chilkat.CkStringBuilder() success = http.QuickGetSb("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1",sbResponseBody) if (success == False): print(http.lastErrorText()) sys.exit() jResp = chilkat.CkJsonObject() jResp.LoadSb(sbResponseBody) jResp.put_EmitCompact(False) print("Response Body:") print(jResp.emit()) respStatusCode = http.get_LastStatus() print("Response Status Code = " + str(respStatusCode)) if (respStatusCode >= 400): print("Response Header:") print(http.lastHeader()) print("Failed.") sys.exit() # Sample output: # { # "page_count": 1, # "page_number": 1, # "page_size": 30, # "total_records": 1, # "users": [ # { # "id": "s8uAiMJiRmS_-eu1yOhKlg", # "first_name": "Joe", # "last_name": "Example", # "email": "joe@example.com", # "type": 1, # "pmi": 5224934114, # "timezone": "America/Chicago", # "verified": 1, # "created_at": "2021-07-30T11:56:37Z", # "last_login_time": "2021-07-30T11:56:37Z", # "language": "en-US", # "phone_number": "", # "status": "active", # "role_id": "0" # } # ] # } # Sample code for parsing the JSON response... # Use the following online tool to generate parsing code from sample JSON: # Generate Parsing Code from JSON page_count = jResp.IntOf("page_count") page_number = jResp.IntOf("page_number") page_size = jResp.IntOf("page_size") total_records = jResp.IntOf("total_records") i = 0 count_i = jResp.SizeOfArray("users") while i < count_i : jResp.put_I(i) id = jResp.stringOf("users[i].id") first_name = jResp.stringOf("users[i].first_name") last_name = jResp.stringOf("users[i].last_name") email = jResp.stringOf("users[i].email") v_type = jResp.IntOf("users[i].type") pmi = jResp.IntOf("users[i].pmi") timezone = jResp.stringOf("users[i].timezone") verified = jResp.IntOf("users[i].verified") created_at = jResp.stringOf("users[i].created_at") last_login_time = jResp.stringOf("users[i].last_login_time") language = jResp.stringOf("users[i].language") phone_number = jResp.stringOf("users[i].phone_number") status = jResp.stringOf("users[i].status") role_id = jResp.stringOf("users[i].role_id") i = i + 1 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.