简体   繁体   English

我可以使用 Microsoft Graph API 在 MS Teams 上的所有团队/组中搜索文件吗

[英]Can I search for a file through all the teams/groups I belong to on MS Teams using the Microsoft Graph API

I have been using the following API where I suggest the TEAM_ID/GROUP_ID to search我一直在使用以下 API 我建议在其中搜索 TEAM_ID/GROUP_ID

https://graph.microsoft.com/v1.0/groups/GROUP_ID/drive/root/search(q= 'SEARCH_VALUE') https://graph.microsoft.com/v1.0/groups/GROUP_ID/drive/root/search(q= 'SEARCH_VALUE')

I'd rather want to search in all the groups I am a part of without the Group ID to search the contents in the Teams Drive.我宁愿在没有组 ID 的情况下搜索我所属的所有组以搜索 Teams Drive 中的内容。 Any leads will be appreciated.任何线索将不胜感激。

The group_id is required, see here . group_id 是必需的,请参见此处 在此处输入图像描述

You could try Powershell to get the groups that you want, then loop to request MS Graph API.您可以尝试 Powershell 来获取您想要的组,然后循环请求 MS Graph API。

#sign in your azure account
Connect-AzureAD

#get access token
function Get-AzureRMBearerToken
{
    [CmdletBinding()]
    Param
    (
        $TenantID,

        $AppID,

        $ClientSecret
    )

    $Result=Invoke-RestMethod -Uri https://login.microsoftonline.com/$TenantID/oauth2/token?api-version=1.0 -Method Post -Body @{"grant_type" = "client_credentials"; "resource" = "https://graph.microsoft.com/"; "client_id" = "$AppID"; "client_secret" = "$ClientSecret" }
    $Authorization = "{0} {1}" -f ($result.token_type , $result.access_token)
    $Authorization
}
$accessToken = Get-AzureRMBearerToken  -TenantID "{your tenant id}" -AppID "{application/client id}" -ClientSecret "{value in your client secret}"

#get all groups
$groups = Get-AzureADGroup -All

#request MS Graph API in the loop
Foreach($group in $groups){
    $url = "https://graph.microsoft.com/v1.0/groups/"+$group.ObjectId+"/drive/root/search(q='SEARCH_VALUE')"
    Invoke-RestMethod -Method Get -Uri $url -Headers @{ Authorization = $accessToken }
} 

Note: Make sure your application has the required permissions.注意:确保您的应用程序具有所需的权限。 Refer to here and here .请参阅此处此处

I found the solution by using Search Drive Items which is currently available in Beta from Graph API.我通过使用 Graph API 目前在 Beta 版中提供的 Search Drive Items 找到了解决方案。 It searches the list of files in detail from all the team drives and Sharepoint drives you have access to under the azure tenant.它会从您可以在 azure 租户下访问的所有团队驱动器和 Sharepoint 驱动器中详细搜索文件列表。

O365 Groups are the foundation of many things in Microsoft's cloud world, a team is an add-on to office 365 groups, as is Sharepoint (where the team files are mostly stored) O365 组是微软云世界中许多事物的基础,团队是 Office 365 组的附加组件,Sharepoint 也是如此(团队文件主要存储在其中)

I don't believe that there is a single graph query that can return all drive files that you have access to.我不相信有一个图形查询可以返回您有权访问的所有驱动器文件。 you would have to build 2 queries, one to query the groups you are a member of, and then loop through it to do a search query on each of the groups.您将必须构建 2 个查询,一个查询您所属的组,然后循环通过它对每个组进行搜索查询。 to get all group ids of groups you are a member of is /getMemberGroups https://docs.microsoft.com/en-us/graph/api/user-getmembergroups?view=graph-rest-1.0&tabs=http获取您所属的组的所有组 ID 是 /getMemberGroups https://docs.microsoft.com/en-us/graph/api/user-getmembergroups?view=graph-rest-1.0&tabs=http

You can probably do it with powershell or a simple program or really any language that can call graph.您可能可以使用 powershell 或一个简单的程序或任何可以调用图形的语言来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM