如何创建一个小的python代码来获取团队调用的参与者列表?

xuo3flqw  于 2023-05-16  发布在  Python
关注(0)|答案(2)|浏览(96)

bounty还有3天到期。回答此问题可获得+300声望奖励。Alex想要引起更多关注这个问题:这个主题似乎是令人难以置信的复杂和混乱,只有一个真实的的Maven在微软可能能够回答这个问题!这个问题是来自超级用户的migrated,因为它可以在Stack Overflow上回答。Migrated 10天前.

使用python,并有一个azure applicationID/ objectID/ tenantID / clientID和clientSecret我想访问一个“团队”会议,使用例如requests获取正在进行的团队会议的参与者列表。用google和chatgtp搜索后,在现有和非现有模块之间似乎有很多混淆,比如msgraphmsgraph-sdkmsgraph-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,不幸的是,我必须请求访问,我不知道是否有人会回复我的请求。

kknvjkwl

kknvjkwl1#

您可以使用下面的python代码来获取团队通话的参与者列表:

#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())

我注册了一个Azure AD应用程序并授予了**API permissions**如下:

最初,我运行下面的代码来获取有关调用的详细信息,如下所示:

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())

答复:

类似地,你可以运行下面的python代码来获取团队调用的参与者列表

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())

答复:

5gfr0r5j

5gfr0r5j2#

要访问Microsoft Teams API并检索正在进行的Teams调用中的参与者列表,您可以将requests库与Microsoft Graph API沿着使用。下面是一个小的Python代码片段,演示了如何实现这一点:

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'])


请确保将'YOUR_CLIENT_ID'、'YOUR_CLIENT_SECRET'、'YOUR_TENANT_ID'和'YOUR_CALL_ID'替换为您的实际Azure AD凭据和要为其检索参与者的团队呼叫的ID。
此代码段使用requests库向Microsoft Graph API发送HTTP请求。它首先使用Azure AD凭据获取访问令牌。然后,它向Teams API端点发出GET请求,以获取指定调用的参与者。最后,它处理响应JSON以提取和打印参与者的显示名称。
请注意,如果您还没有requests库,则可能需要安装它。您可以使用pip install requests来安装它。

相关问题