Failed to refresh tokens: {response.status_code} {response.text}

Description
I’m not able to access the token through pyzoom. It was working perfectly fine before so I’m a bit confused. I checked the client ID and secret to see if they changed, but they didn’t. I even tried making a new app, but it didn’t work either.

Error
The error message I’m getting is Failed to refresh tokens: {response.status_code} {response.text}

How To Reproduce

  1. Create a connection to Zoom’s API through pyzoom.
import os
from pyzoom import oauth_wizard, ZoomClient

client = ZoomClient(oauth_wizard(os.getenv('CLIENT_ID'), os.getenv('CLIENT_SECRET'))["access_token"])
  1. It’ll redirect you to the redirect URI. Press “Allow”.
  2. Error message pops up.

Hi @vtrinh , pyzoom is not a Zoom created product. On the disclaimer description it says “This library is not related to Zoom Video Communications, Inc. It’s an open-source project that aims to simplify working with this suddenly very popular service.” Please reach out to the creators for support.

If other community members see this and have familiarity, they are more than inclined to assist further here :slight_smile:

I rewrote my code to not include the pyzoom module to see if that was the issue, but I’m still getting an error.

{'reason': 'Invalid Grant', 'error': 'invalid_grant'}

This is my new code:

from requests import post
from base64 import b64encode
import http.server
import webbrowser

CLIENT_ID = "insert client id"
CLIENT_SECRET = "insert client secret"

PORT = 3000
REDIRECT_URI = f"http://localhost:{PORT}"

class ReqHandle(http.server.SimpleHTTPRequestHandler):
    def do_GET(self) -> None:
        self.send_response(200)
        self.server.auth_code = self.path.split("/?code=")[1] # ugly

webbrowser.open(f"https://zoom.us/oauth/authorize?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}")

server = http.server.HTTPServer(("", PORT), ReqHandle)
server.handle_request()

auth_code = server.auth_code

headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Basic " + b64encode(f"{CLIENT_ID}:{CLIENT_SECRET}".encode()).decode()
}

data = {
    "code": auth_code,
    "redirect_uri": REDIRECT_URI,
    "grant_type": "authorization_code",
}

r = post("https://zoom.us/oauth/token", headers=headers, data=data)
print(r.json())

Hi @vtrinh , I see authorization and an attempt for an access token. Check out the sample code for refresh token on our Postman workspace: Postman

From what I understand, the refresh token request requires an access token as part of the request body. Unfortunately, due to the nature of our setup, since we were in rapid testing we would request and immediately discard access tokens after one use. This means I do not have an access token from any previous attempts that I could potentially refresh.

@vtrinh ,

You should be caching your refresh token supplied with the access token, and use the refresh token to refresh access token. Refresh tokens expire after 90 days. Please see the guidance here: OAuth for user authorized apps

Additionally, you do not need to re-auth each time you request an access token or refresh an access token.

Thank you for the follow up. Our original problem is still there: we cannot authorize any new tokens, and have no tokens to attempt a refresh on since we did not cache the refresh token before. The same error applies: “invalid grant”. Are there any other tips you can provide that would help with this immediate issue?

Hi @vtrinh , please try your conditions in the sample environment via postman from the link I shared. I am able to successfully grab a token. Click “overview” to see the documentation. If you’re able to generate a token in Postman, it’s like your code that needs to be reconfigured.