skip to Main Content

Using python, and having an azure applicationID/ objectID/ tenantID / clientID and clientSecret I want to access a "teams" meeting using e.g. requests to get the list of participants of an ongoing teams meeting. Having searched with google and using chatgtp, there seems to be a lot of confusion between existing and non-exsting modules like msgraph,
msgraph-sdk and msgraph-sdk-python. They all do not seem to work, or they work differently.

I appreciate a small code python snippet that actually works, and that I can use to get the list of participants of an ongoing Teams call.

I had a code like the following which does not work:

from microsoftgraph.client import Client    

client = Client(client_id, client_secret, account_type='common')


# Make a GET request to obtain the list of participants
call_id = '123 456 789'
response = client.get(f'/communications/calls/{call_id}/participants', headers={'Authorization': f'Bearer {access_token}'})
participants = response.json()

Error:

AttributeError: 'Client' object has no attribute 'get'

I also found this quick start guide in which I unfortunately have to request access, and I will not know if someone ever will reply to my request.

2

Answers


  1. You can use below python code to get the list of participants of a teams call:

    #pip install azure.identity
    #pip install msgraph.core
    #pip install json_extract
    
    from azure.identity import ClientSecretCredential
    from msgraph.core import GraphClient
    
    credential = ClientSecretCredential(tenant_id='tenantID',client_secret='secret',client_id='appID')
    client = GraphClient(credential=credential)
    result = client.get('/communications/calls/<callID>/participants')
    
    print(result.json())
    

    I registered one Azure AD application and granted API permissions as below:

    enter image description here

    Initially, I ran below code to get details regarding the call like this:

    from azure.identity import ClientSecretCredential
    from msgraph.core import GraphClient
    
    credential = ClientSecretCredential(tenant_id='tenantID',client_secret='secret',client_id='appID')
    client = GraphClient(credential=credential)
    result = client.get('/communications/calls/<callID>/')
    
    print(result.json())
    

    Response:

    enter image description here

    Similarly, you can run below python code to get the list of participants of a teams call:

    from azure.identity import ClientSecretCredential
    from msgraph.core import GraphClient
    
    credential = ClientSecretCredential(tenant_id='tenantID',client_secret='secret',client_id='appID')
    client = GraphClient(credential=credential)
    result = client.get('/communications/calls/<callID>/participants')
    
    print(result.json())
    

    Response:

    enter image description here

    Login or Signup to reply.
  2. To access Microsoft Teams API and retrieve the list of participants in an ongoing Teams call, you can use the requests library along with the Microsoft Graph API. Here’s a small Python code snippet that demonstrates how to achieve this:

    import requests
    
    # Azure AD credentials
    client_id = 'YOUR_CLIENT_ID'
    client_secret = 'YOUR_CLIENT_SECRET'
    tenant_id = 'YOUR_TENANT_ID'
    
    # Get access token
    token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'
    token_payload = {
        'grant_type': 'client_credentials',
        'client_id': client_id,
        'client_secret': client_secret,
        'scope': 'https://graph.microsoft.com/.default'
    }
    response = requests.post(token_url, data=token_payload)
    access_token = response.json()['access_token']
    
    # Teams call ID
    call_id = 'YOUR_CALL_ID'
    
    # Get participants
    participants_url = f'https://graph.microsoft.com/v1.0/communications/calls/{call_id}/participants'
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'application/json'
    }
    response = requests.get(participants_url, headers=headers)
    participants = response.json()
    
    # Process participants
    if 'value' in participants:
        for participant in participants['value']:
            print(participant['user']['displayName'])
    ```
    
    Make sure to replace `'YOUR_CLIENT_ID'`, `'YOUR_CLIENT_SECRET'`, `'YOUR_TENANT_ID'`, and `'YOUR_CALL_ID'` with your actual Azure AD credentials and the ID of the Teams call you want to retrieve the participants for.
    
    This code snippet uses the `requests` library to send HTTP requests to the Microsoft Graph API. It first obtains an access token using your Azure AD credentials. Then, it makes a GET request to the Teams API endpoint to fetch the participants of the specified call. Finally, it processes the response JSON to extract and print the display names of the participants.
    
    import requests
    
    # Azure AD credentials
    client_id = 'YOUR_CLIENT_ID'
    client_secret = 'YOUR_CLIENT_SECRET'
    tenant_id = 'YOUR_TENANT_ID'
    
    # Get access token
    token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'
    token_payload = {
        'grant_type': 'client_credentials',
        'client_id': client_id,
        'client_secret': client_secret,
        'scope': 'https://graph.microsoft.com/.default'
    }
    response = requests.post(token_url, data=token_payload)
    access_token = response.json()['access_token']
    
    # Teams call ID
    call_id = 'YOUR_CALL_ID'
    
    # Get participants
    participants_url = f'https://graph.microsoft.com/v1.0/communications/calls/{call_id}/participants'
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'application/json'
    }
    response = requests.get(participants_url, headers=headers)
    participants = response.json()
    
    # Process participants
    if 'value' in participants:
        for participant in participants['value']:
            print(participant['user']['displayName'])
    

    Make sure to replace ‘YOUR_CLIENT_ID’, ‘YOUR_CLIENT_SECRET’, ‘YOUR_TENANT_ID’, and ‘YOUR_CALL_ID’ with your actual Azure AD credentials and the ID of the Teams call you want to retrieve the participants for.

    This code snippet uses the requests library to send HTTP requests to the Microsoft Graph API. It first obtains an access token using your Azure AD credentials. Then, it makes a GET request to the Teams API endpoint to fetch the participants of the specified call. Finally, it processes the response JSON to extract and print the display names of the participants.

    Please note that you may need to install the requests library if you don’t have it already. You can install it using pip install requests.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search