Първоначално изпратено от ratten
Разгледай мнение
write a python script to request the token
И ми отговаря:
import requests
# Set your Azure AD tenant ID, client ID, and client secret here
tenant_id = 'YOUR_TENANT_ID'
client_id = 'YOUR_CLIENT_ID'
client_secret = 'YOUR_CLIENT_SECRET'
# Set the scope for the Microsoft API (in this case, Microsoft Graph)
scope = 'https://graph.microsoft.com/.default'
# Define the token URL
token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'
# Define the data payload to send to the token endpoint
data = {
'client_id': client_id,
'scope': scope,
'client_secret': client_secret,
'grant_type': 'client_credentials'
}
# Send the POST request to fetch the access token
response = requests.post(token_url, data=data)
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response to get the access token
token_response = response.json()
access_token = token_response.get('access_token')
print("Access Token:", access_token)
else:
# Print the error if the request failed
print(f"Failed to retrieve token: {response.status_code}")
print(response.text)
И най-важното: работи.
Джуниърчето (което ще изгуби половин ден да търси в гугъла как да го направи) става излишно.
Още по-важно: разбира какво го питам. Ако сбърка някъде му правя забележка и го оправя веднага. Все едно имаш 4-5 джуниъра, които бачкат за теб.
За телефонния бот пък може да изглежда като манекенка, да говори на видео чат и то на по-добър английски (или какъвто там език избереш) от Камила Харис и да разбира какво питаш дори да питаш на шотландски диалект. Между 2015 и сега са светове.
Коментар