I am trying to retrieve the sites that the user is following from Microsoft Graph Explorer.
I found this document to do that:
If you're accessing the Graph API from any other interface (e.g. code), you'll need to manually form the request headers and include the token that you've obtained.
How to obtain a token for a service application would require further information, you can read more from the official documentation
Here is a simple example using Python and MSAL, as well as the constructed request header.
app = msal.ConfidentialClientApplication(
client_id = client_id,
client_credential = client_secret,
authority = f"https://login.microsoftonline.com/{tenant_id}")
scopes = ["https://graph.microsoft.com/.default"]
token = None
token = app.acquire_token_for_client(scopes = scopes)
req_headers = {
"Authorization": "Bearer " token['access_token']
}