我正在开发flask应用程序,从ms graph api收集数据并更新ms团队。我正在使用微软的python模板应用程序来实现这一点。当我调用api get来获取团队的通道列表时,它会返回不稳定的值。大多数情况下,返回值中缺少一些通道,而ms团队上显示该通道存在。在更新或添加通道后的第一次调用之后,再调用几次get之后,这种情况会得到改善,但仍然不一致。ms-api在定期get调用中返回不一致结果的原因是什么?我需要在这些调用之间实现暂停/中断吗?我感谢你的帮助。
@app.route("/graphcall")
def graphcall():
token = _get_token_from_cache(app_config.SCOPE)
if not token:
return redirect(url_for("login"))
headers = {'Authorization': 'Bearer ' + token['access_token']}
teamInfo = teamInfo_func()
graph_data = requests.get(
app_config.ENDPOINT + '/users/?$filter=userType eq \'guest\'',
headers=headers,
)
## some work on graph_data
graph_data = requests.get(
app_config.ENDPOINT + '/teams/%s/members'%teamInfo[1],
headers=headers,
)
## some work on graph_data
graph_data = requests.get(
app_config.ENDPOINT + '/teams/%s/channels'%teamInfo[1],
headers=headers,
)
## some work on graph_data
teams_data = graph_data.json()
for channel in teams_data['value']:
graph_data = requests.get(
app_config.ENDPOINT + '/teams/%s/channels/%s/members'%(teamInfo[1], channel['id']),
headers=headers,
)
## some work on graph_data
try:
# to Add
for i in toAdd_df['...'].unique():
toAdd_temp_df = toAdd_df[toAdd_df['...']==i].reset_index(drop=True)
if toAdd_temp_df.loc[0, '...']==1:
name = ...
email = ...
url = app_config.ENDPOINT + '/invitations'
invite_obj = {
"invitedUserDisplayName": "%s"%name,
"invitedUserEmailAddress": email,
"sendInvitationMessage": False,
"inviteRedirectUrl": "..."
}
result = requests.post(url, json = invite_obj, headers = headers)
if result.status_code==201:
user_ID = ...
url = app_config.ENDPOINT + '/teams/%s/members'%teamInfo[1]
add_obj = {
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": ["Guest"],
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('%s')"%user_ID
}
result = requests.post(url, json = add_obj, headers = headers)
if result.status_code==201:
for j in toAdd_temp_df['...'].values:
channel_ID = ...
url = app_config.ENDPOINT + '/teams/%s/channels/%s/members'%(teamInfo[1], channel_ID)
add_obj = {
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": ["Guest"],
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('%s')"%user_ID
}
result = requests.post(url, json = add_obj, headers = headers).
if result.status_code==201:
...
else:
user_ID = ...
for j in toAdd_temp_df['...'].values:
if j not in df_teams['...'].values:
url = app_config.ENDPOINT + '/teams/%s/channels'%teamInfo[1]
channel_obj = {
"displayName": j,
"description": "...",
"membershipType": "private"
}
result = requests.post(url, json = channel_obj,headers = headers)
if result.status_code==201:
channel_ID = ...
url = app_config.ENDPOINT + '/teams/%s/channels/%s/members'%(teamInfo[1], channel_ID)
add_obj = {
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": ["Guest"],
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('%s')"%user_ID
}
result = requests.post(url, json = add_obj, headers = headers)
if result.status_code==201:
...
else:
print(result.json())
else:
print(result.json())
else:
channel_ID = ...
url = app_config.ENDPOINT + '/teams/%s/channels/%s/members'%(teamInfo[1], channel_ID)
add_obj = {
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": ["Guest"],
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('%s')"%user_ID
}
result = requests.post(url, json = add_obj, headers = headers)
if result.status_code==201:
...
else:
print(result.json())
# to Rem/Del
toRem_df = df_channels[df_channels['...']==1].reset_index(drop=True)
for i in toRem_df['...'].unique():
toRem_temp_df = toRem_df[toRem_df['...']==i].reset_index(drop=True)
if toRem_temp_df.loc[0, '...']==1:
membership_ID = df_teams_members[df_teams_members['...']==i]['...'].item()
url = app_config.ENDPOINT + '/teams/%s/members/%s'%(teamInfo[1], membership_ID)
result = requests.delete(url, headers=headers)
if result.status_code==204:
...
else:
print(result.json())
else:
for j in toRem_temp_df['...'].values:
temp_temp = toRem_temp_df[toRem_temp_df['...']==j]
channel_ID = temp_temp.loc[0, '...']
membership_ID = temp_temp.loc[0, '...']
url = app_config.ENDPOINT + '/teams/%s/channels/%s/members/%s'%(teamInfo[1], channel_ID, membership_ID)
result = requests.delete(url, headers=headers)
if result.status_code==204:
...
else:
print(result.json())
except Exception as e:
...
暂无答案!
目前还没有任何答案,快来回答吧!