Hi there I am using replit to write a telegram bot that updates the user input to a excel file. I connected ms graph api to my code. It didn't worked I mean worked but the excel file wasn't updated. So I tried getting the access token which was a success and then implemented that code the error wasn't resolved so I tried connecting it through the manual authorization process the login screen to permit the access token it showed another eror then I came over this..
No matter what I am trying whateber I am adding in the azure portal the link remains the same. My get access token function
import logging
import msal
from hi import CLIENT_ID, TENANT_ID
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("main")
SCOPES = ["https://graph.microsoft.com/.default"]
def get_access_token():
authority = f"https://login.microsoftonline.com/{TENANT_ID}"
app = msal.PublicClientApplication(CLIENT_ID, authority=authority)
try:
result = app.acquire_token_interactive(scopes=SCOPES)
access_token = result.get('access_token')
if access_token:
return access_token
else:
error_msg = result.get('error_description', result.get('error', 'Unknown error'))
logger.error(f"Failed to retrieve access token: {error_msg}")
raise Exception(f"Could not retrieve access token: {error_msg}")
except Exception as e:
logger.error(f"Exception while retrieving access token: {str(e)}")
raise
# Example usage:
try:
token = get_access_token()
print("Access token:", token)
except Exception as e:
print("Error:", str(e))
![ggyfd](https://learn-attachment.microsoft.com/api/attachments/9f720c58-6c05-46d6-b634-42d1dde97417?platform=QnA)
My Images of at the azure portal are
![png-ms-graph-ss](https://learn-attachment.microsoft.com/api/attachments/312c1399-a491-4c38-b742-c7dddca5390a?platform=QnA)
![ssjhhu](https://learn-attachment.microsoft.com/api/attachments/66635280-c69f-42f0-9744-958d636e270a?platform=QnA)
![ssgfhgjh](https://learn-attachment.microsoft.com/api/attachments/2f8c85b9-b73a-4f60-a6f4-31b92d80a205?platform=QnA)