shauntarves/wyze-sdk

How to handle "access token has expired" errors?

Closed this issue · 3 comments

Hi Shaun,

Sorry if this is documented elsewhere, but I just got my first "WyzeApiError: The access token has expired. Please refresh the token and try again." error from the SDK. What is the process to use the refresh_token you get when you login for the first time?

Actually, I see Issue 72 here. and I see the code fragment from @anshuarya:

response=client.refresh_token()
client._token = response["data"]["access_token"]
client._refresh_token = response["data"]["refresh_token"]

But my app doesn't run continuously. Is there nothing to be done except re-login and get a new access token each time I run my script?

You can refresh an access token for quite a while. I just refreshed one last night that had been created like over a month ago. Just make sure you store the new access token and refresh token

Just a note here, if you restart your application, simply save your tokens to a file first then read them back when your application starts again :) I can add some code samples if needed since this is exactly what I did for a project as well.