Get Federal User Activity Status Microsoft Graph API

  Kiến thức lập trình

I’m looking for a way to retrieve the activity status of federated users in bulk for external companies via API, without the need to invite the users and wait for them to accept the invitation.

Is it possible to obtain the same activity status response as when using the search bar in Teams, even if not using the Graph API but other methods? Currently, this method only provides an “offline” status or “presence unknown” for all federated users.

Any help or suggestions would be greatly appreciated.

Thank you!

import requests
import json
from dotenv import load_dotenv
from msal import ConfidentialClientApplication


load_dotenv(dotenv_path=r'....')


CLIENT_ID = os.getenv('CLIENT_ID')
CLIENT_SECRET = os.getenv('CLIENT_SECRET')
TENANT_ID = os.getenv('TENANT_ID')

app = ConfidentialClientApplication(
CLIENT_ID,
authority=f"https://login.microsoftonline.com/{TENANT_ID}",
client_credential=CLIENT_SECRET,)

result = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])

if "access_token" in result:
access_token = result["access_token"]
else:
print("Error acquiring token:", result.get("error"), result.get("error_description"))
exit(1)

user_id = "..."

presence_url = f'https://graph.microsoft.com/beta/communications/presences/{user_id}'
presence_headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'}

response = requests.get(presence_url, headers=presence_headers)

if response.status_code == 200:
presence_info = response.json()
print("Presence Info:", json.dumps(presence_info, indent=2))

else:
print("Failed to retrieve presence info:", response.status_code, response.text)

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT