-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS2Saccesstoken.py
39 lines (33 loc) · 1.1 KB
/
S2Saccesstoken.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import requests
import base64
import os
from dotenv import load_dotenv
# Set up the API credentials
load_dotenv()
client_id = os.getenv("ZOOM_CLIENTID")
client_secret = os.getenv("ZOOM_CLIENTSECRET")
account_id = os.getenv("ZOOM_ACCOUNTID")
# Encode the client ID and secret in base64 format
auth_string = f"{client_id}:{client_secret}"
auth_bytes = auth_string.encode("ascii")
base64_bytes = base64.b64encode(auth_bytes)
base64_string = base64_bytes.decode("ascii")
# Set up the headers for API requests
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"Basic {base64_string}"
}
# Set up the data for the token API request
data = {
"grant_type": "account_credentials",
"account_id": account_id
}
# Send a POST request to the token API to get an access token
url = "https://zoom.us/oauth/token"
response = requests.post(url, data=data, headers=headers)
# Parse the JSON response and extract the access token
if response.status_code == 200:
token = response.json()["access_token"]
print(f"Access token: {token}")
else:
print("Error getting access token")