6

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. 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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Alex
  • 41,580
  • 88
  • 260
  • 469
  • Based on their [pip page](https://pypi.org/project/microsoftgraph-python/) they do not have a `get` method. You can directly have access to the attribute. Also, the event and attendee resource types seem to be what you are you looking for. – MufasaChan May 05 '23 at 14:09
  • @MufasaChan How can I get access to that attribute? The word "Teams" is not mentioned once on the page you have linked. – Alex May 07 '23 at 08:49
  • You are right, I just pointing misuse of the Client object. This microsoftgraph-python seems to be a lightweight wrapper of their APIs. I do not know the limit of this wrapper. One full lower-level package seems to be msgraph-sdk-python. With this package you can do regular HTTP request based on their rest API. You have the [graph explorer](https://developer.microsoft.com/en-us/graph/graph-explorer/). There are tabs on the left of request for every apps they have, including teams. The meetings seem to be attached to the callendar though, not Teams. Check the ressource types mentionned – MufasaChan May 07 '23 at 09:36
  • @MufasaChan Thanks for that description, but I do not see a relevant API attached to the calendar. I see like "schedule a meeting" or "find a meeting", but I do not see "meeting members" or anything. Maybe I have to use "Microsoft Teams (beta)"l here I see :list members of a chat"! But maybe chat is not a meeting or maybe it is? And then I need to set permissions. There are like "Chat.Read", "Chat.BasicRead". and for every SINGLE one of them I have to request approval? Who is about to approve that request? – Alex May 12 '23 at 07:13
  • By looking at the API doc, you have the `meetingAttendanceReport` that is a list of `attendee` (see doc for these objetcs). On the pages [`Online Meeting Artificats`](https://learn.microsoft.com/en-us/graph/cloud-communications-online-meeting-artifacts) and [Getting onlineMeeting](https://learn.microsoft.com/en-us/graph/api/onlinemeeting-get?view=graph-rest-1.0&tabs=http) there are examples of how to access it. From these info + API interface, I think you can find what you want. Plus, on the graph explorer, go to tab "Ressources" and type "attendee" to find example of API requests. – MufasaChan May 12 '23 at 08:40
  • 1
    @MufasaChan Thanks for that info, but without a proper python module or the permissions etc. I need for these apps/artifacts/resources I guess I have no way of trying them out... – Alex May 12 '23 at 09:08
  • Try this solution: https://softans.com/question/how-to-create-a-small-python-code-to-get-a-list-of-participants-of-a-teams-call/#comment-512 – GHULAM NABI May 19 '23 at 07:08
  • @GHULAMNABI Thanks for the link, but how to do "Please note that you need the necessary permissions and valid Azure AD application credentials to access the Microsoft Graph API."? What permissions do I need for the task at hand? Where to click? Who is granting these permissions? – Alex May 30 '23 at 08:07
  • I give up on this question. It is not possible to solve in a lifetime. Also I have not the permissions I need, it seems, so a waste of time. Thanks for the help ... – Alex May 30 '23 at 08:21

2 Answers2

2

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

Reference:

List participants - Microsoft Graph v1.0

Sridevi
  • 10,599
  • 1
  • 4
  • 17
  • Thanks for the reply, but I get an error `ModuleNotFoundError: No module named 'msgraph.core'` although the pip install of that module seem to have worked fine. – Alex May 12 '23 at 07:25
  • In addition, why would I need permission for "Calls.Initiate.All"? That "sounds" like to me to initiate calls, which is NOT what I want. – Alex May 12 '23 at 07:29
  • 1
    To run `GET /communications/calls/{id}/participants`, check the required permissions mentioned in this [MS Doc](https://learn.microsoft.com/en-us/graph/api/call-list-participants?view=graph-rest-1.0&tabs=http#permissions). – Sridevi May 12 '23 at 07:33
  • Ah there I can see that. Yes the I guess you are right although it does not make any sense from the naming. My company might not allow these permissions anyway, so I guess there is nothing I can do. But it seems this Azure stuff is anyway EXTREMLY complicated and user unfriendly. – Alex May 12 '23 at 07:38
0
import requests

# Replace with your own values
access_token = 'YOUR_ACCESS_TOKEN'
call_id = 'CALL_ID'

# Make a GET request to the Microsoft Graph API
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(url, headers=headers)

# Check the response status code
if response.status_code == 200:
    participants = response.json()['value']

    # Print the participants' names
    for participant in participants:
        print(participant['displayName'])
else:
    print(f"Error retrieving participants: {response.status_code} - {response.text}")

I guess this will work

Ali Hamza
  • 67
  • 6
  • Hello sorry for the late reply, but where do I get the access token? I have a "application ID', "client ID', "object ID', "directory ID", "tenant ID", "Client secret value " and a "client secret ID" ... – Alex May 30 '23 at 07:03
  • Set up an Azure AD application: Register an application in the Azure portal to obtain a client ID and client secret. This will allow your application to authenticate and obtain access tokens. Grant necessary permissions: Configure the required permissions for your application to access the Microsoft Graph API. This can be done in the Azure portal or through Microsoft Graph API permissions consent. – Ali Hamza Jun 07 '23 at 06:06
  • Obtain an authorization code: Redirect the user to the Microsoft login page, where they will authenticate and grant consent for the application to access their resources. After successful authentication, the user will be redirected to the specified redirect URI with an authorization code. Exchange authorization code for an access token: Using the authorization code received in the previous step, make a POST request to the Azure AD token endpoint to exchange it for an access token. Include the client ID, client secret, redirect URI, and other required parameters. – Ali Hamza Jun 07 '23 at 06:06
  • Receive and use the access token: Upon successful exchange, the token endpoint will respond with an access token. You can use this token to authenticate subsequent requests to the Microsoft Graph API by including it in the 'Authorization' header. The exact steps and configurations may vary depending on your specific scenario and application type (web app, native app, etc.). It is recommended to refer to the Microsoft documentation for detailed instructions and code samples specific to your programming language and platform. – Ali Hamza Jun 07 '23 at 06:06
  • Here is the official Microsoft documentation that provides more information on obtaining access tokens: https://learn.microsoft.com/en-us/azure/active-directory/develop/ You can find language-specific samples and libraries in the Microsoft GitHub repositories: https://github.com/AzureAD/microsoft-authentication-library-for-python – Ali Hamza Jun 07 '23 at 06:09
  • and i am really sorry for late reply – Ali Hamza Jun 07 '23 at 06:09
  • I cannot grant the permissions. Also, there are like 200 API endpoints with like 10 different ways permissions can be granted. That alone makes 2000 possibilities. And I have no idea who could grant these permissions. Anyway, it is not important. But for sure I will run away from Azure in the future! – Alex Jun 07 '23 at 06:10
  • well i dont know much about it sorry cause i have never used it i will surely try helping you please give me some time – Ali Hamza Jun 07 '23 at 06:12
  • No worries. It is not important. Please do not waste your time on this issue. I gave up... – Alex Jun 07 '23 at 06:13
  • If you are facing difficulties granting permissions and finding the appropriate API endpoints, it can be helpful to consult the Microsoft Graph API documentation specific to the functionality you are trying to implement. The documentation typically provides guidance on required permissions and the necessary steps to configure them. It's also worth considering reaching out to the Azure support channels or community forums for assistance. Microsoft offers support resources to help developers and users with their Azure-related queries.well this is what the gpt says – Ali Hamza Jun 07 '23 at 06:14
  • you can try alternative of azure like Amazon web services, Google cloud platform, IBM cloud, Alibaba cloud, etc – Ali Hamza Jun 07 '23 at 06:16