Search⌘ K

Refresh Access Token

Discover how to refresh the Blogger API access token in Python by running code that updates the ACCESS_TOKEN and its expiry. Learn to manage and save your CLIENT_ID, CLIENT_SECRET, ACCESS_TOKEN, REFRESH_TOKEN, and expiry values to keep your API requests authorized and secure.

We'll cover the following...

Generate refreshed API keys

Click the "Run" button in the widget below to refresh the ACCESS_TOKEN.

Note: Make sure the values for the CLIENT_ID, CLIENT_SECRET, ACCESS_TOKEN, REFRESH_TOKEN, and EXPIRY are already set.

Python 3.8
from google.oauth2.credentials import Credentials
try:
credentials = Credentials.from_authorized_user_file('token.json')
refresh_token(credentials)
except:
print("Please enter your access token data in the token.json file")

The above code generates a new value for the ACCESS_TOKEN with a new EXPIRY. These two values along with the REFRESH_TOKEN are displayed and extracted from the output to be saved as API keys.

Click the "Save" button to save the keys.