bounty还有3天到期。回答此问题可获得+300声望奖励。Alex想要引起更多关注这个问题:这个主题似乎是令人难以置信的复杂和混乱,只有一个真实的的Maven在微软可能能够回答这个问题!这个问题是来自超级用户的migrated,因为它可以在Stack Overflow上回答。Migrated 10天前.
使用python,并有一个azure applicationID/ objectID/ tenantID / clientID和clientSecret我想访问一个“团队”会议,使用例如requests
获取正在进行的团队会议的参与者列表。用google和chatgtp搜索后,在现有和非现有模块之间似乎有很多混淆,比如msgraph
,msgraph-sdk
和msgraph-sdk-python
。它们似乎都不起作用,或者它们起作用的方式不同。
我欣赏一个实际工作的小代码python片段,我可以使用它来获取正在进行的Teams调用的参与者列表。
我有一个像下面这样的代码,它不起作用:
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()
错误:
AttributeError: 'Client' object has no attribute 'get'
我还发现了this quick start guide,不幸的是,我必须请求访问,我不知道是否有人会回复我的请求。
2条答案
按热度按时间kknvjkwl1#
您可以使用下面的python代码来获取团队通话的参与者列表:
我注册了一个Azure AD应用程序并授予了**
API permissions
**如下:最初,我运行下面的代码来获取有关调用的详细信息,如下所示:
答复:
类似地,你可以运行下面的python代码来获取团队调用的参与者列表:
答复:
5gfr0r5j2#
要访问Microsoft Teams API并检索正在进行的Teams调用中的参与者列表,您可以将
requests
库与Microsoft Graph API沿着使用。下面是一个小的Python代码片段,演示了如何实现这一点: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'])