Microsoft Graph API/search() 在使用纯应用令牌时是否有效 [英] Does Microsoft Graph API /search() work when using app-only token

查看:13
本文介绍了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 注册了一个应用程序,并且已请求并同意API 文档;

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

当我从 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.

我在我的应用程序 (Coldfusion) 中构建 http 请求,而不是使用 SDK.我想知道我是否有编码问题,所以尝试了各种对 url (q='test') 等的搜索部分进行 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.

以上答案基于您的描述:****register app in 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天全站免登陆