使用仅限应用程序的令牌时,Microsoft Graph API/search()是否工作 [英] Does Microsoft Graph API /search() work when using app-only token

查看:46
本文介绍了使用仅限应用程序的令牌时,Microsoft Graph API/search()是否工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用图形API(v1.0)在我们团队的sharepoint/onedrive文件夹中搜索文件和文件夹,但是当使用仅应用程序令牌时,我尝试执行的任何/search(...)请求始终没有任何结果.

I am trying to use the graph API (v1.0) to search for files and folders within our team's sharepoint/onedrive folders but when using an app-only token I consistently get no results for any /search(...) request I try.

我已经在 https://apps.dev.microsoft.com 注册并申请了已请求并同意

I have an registered and application with https://apps.dev.microsoft.com and have requested and granted consent for the permissions stated in the API Documentation;

User.ReadWrite.AllGroup.Read.AllSites.Read.AllSites.ReadWrite.AllGroup.ReadWrite.AllSites.Manage.AllFiles.ReadWrite.AllUser.Read.AllFiles.Read.AllSites.FullControl.All

User.ReadWrite.All, Group.Read.All, Sites.Read.All, Sites.ReadWrite.All, Group.ReadWrite.All, Sites.Manage.All, Files.ReadWrite.All, User.Read.All, Files.Read.All, Sites.FullControl.All

当我从 https://login.microsoftonline.com/请求令牌时,我可以看到授予有效负载中的权限.

When I request a token from https://login.microsoftonline.com/ I can see the granted permissions in the payload.

使用此令牌,我可以使用drive/root

Using this token I can successfully access the drive and retrieve information about its contents using drive/root

我有一个小的测试文件夹结构,其中包含一些简单的文本文件.

I have a small test folder structure that contains a few simple text files.

我可以通过递归调用drives/{driveid}/items/{folderid}/children来构建完整的树结构来确认此令牌是否可以访问我的文件和文件夹.

I can confirm that this token gives me access to my files and folders by calling drives/{driveid}/items/{folderid}/children recursively to build a complete tree structure.

但是,当我尝试在驱动器中搜索我知道存在的文件名或文本短语时,无论使用何种路径或搜索词的组合,我都不会获得任何结果.我从未见过来自仅应用令牌的搜索结果.

However, when I try to search the drive for filenames or text phrases that I know exist I get no results at all, no matter what combination of paths or search terms I use. I've never seen a search result from an app-only token.

我尝试过的例子;

sites/root/drive/search(q='test')

drive/root/search(q='test')

drives/{driveid}/search(q='test')

drives/{driveid}/root/search(q='test')

短语"test"既作为文件名也存在于某些文件的文本内容中.

The phrase "test" exists both as a filename and also within the text content of some of the files.

我得到一个HTTP:200响应,但是值集合https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)始终为空.

I get an HTTP:200 response but the value collection https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem) is always empty.

我在应用程序中建立http请求(Coldfusion),而不是使用SDK. 我想知道我是否遇到编码问题,因此尝试了各种方法来对url (q='test')的url的搜索部分进行url编码. 我也尝试过用Postman和cUrl运行相同的请求,但结果是相同的.空的.

I'm building http requests in my application (Coldfusion), not using a SDK. I wondered if I was having encoding problems so have tried various approaches of url-encoding the search part of the url (q='test') etc. I've also tried running the same requests with Postman and cUrl but the results are the same. Empty.

唯一有效的方法是,当我使用Graph Explorer尝试相同的搜索时,我得到了希望看到的结果.

The only thing that works is when I try the same searches using the Graph Explorer I get the results I would expect to see.

我知道Explorer使用不同类型的令牌,因此我想知道这是否是令牌以及与我的令牌相关的问题仅适用于应用程序.

I know that Explorer uses a different type of token so I'm wondering if this is and issues related to my token being app-only.

有人知道.../search()是否真正适用于仅应用令牌吗?

Does anyone know if .../search() actually work for app-only tokens?

推荐答案

有人知道.../search()是否真正适用于仅应用程序的令牌吗?

Does anyone know if .../search() actually work for app-only tokens?

答案是肯定的,../search()实际上仅适用于应用专用令牌

根据我的测试,以下搜索API适用于仅应用程序令牌

Based on my test, the following search API works well for app-only token

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

    https://graph.microsoft.com/v1.0/drives/{driveid}/root/microsoft.graph.search(q='test')

    https://graph.microsoft.com/v1.0/drives/{driveid}/microsoft.graph.search(q='test')

https://graph.microsoft.com/v1.0/sites/root/drive/search(q='test')

对于权限配置,只需将" Files.Read.All,Files.ReadWrite.All,Sites.Read.All,Sites.ReadWrite.All "放入项目配置文件中的GraphScopes中,如下所示: 文档状态.

For permission config, just put "Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All" into the GraphScopes in the project config file as docs states.

以上答案基于您的描述:****在 http://中注册应用apps.dev.microsoft.com/ .您可以忽略SDK,尽管它是最佳选择.如果您没有使用GraphScopes进行项目配置,则需要将范围传递给auth请求,操作起来很困难.

Above answer is based on your description:****register app in http://apps.dev.microsoft.com/. You can ignore the SDK although it is the best choice. If you don't have a project config with GraphScopes, you need to pass the scope to auth request, it is difficult for operation.

如果仅限您的应用是指在 SharePoint在线上注册应用 ,则Graph Search API将无法正常工作. SharePoint不会直接与Graph共享AccessToken.

If your app-only mean register app in SharePoint online, then the Graph Search API won't work. SharePoint doesn't share AccessToken with Graph directly.

这篇关于使用仅限应用程序的令牌时,Microsoft Graph API/search()是否工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆