import os import requests import json with open('token.json') as fp: token = json.load(fp)['token'] print(token) token = "THAALHhpO4mmtBUVR6MjRBNUs5NUNDRnhILXhsTEZAhSVBVRmtRc1l5WEZAGZAUl6OENvOEZA0R3NzdUo1akNyMlc4OU93TEpiVnpMRGRTYzVhOG5hcDhQNG9CcnBVd19mb3VfZAkFVQVM5bGRMSGNPVzZAiSHVCODVxUVdNSkJ1MkJYTUFsVW9ucnpwSFdEYlhoN2FId09JVHE1RWttNmZAvV1BYUy1yZA3QtUQZDZD" print(token) CLIENT_ID = os.environ['THREAD_APP_CLIENT_ID'] CLIENT_SECRET = os.environ['THREAD_APP_CLIENT_SECRET'] URL = "https://graph.threads.net/v1.0/access_token" params = { "grant_type": "th_exchange_token", "client_id": CLIENT_ID, "client_secret": CLIENT_SECRET, "access_token": token } response = requests.get(URL, params=params) new_token = response.json()['access_token'] print("New Token: ", new_token) with open('token.json', 'w') as fp: json.dump({'token': new_token}, fp)