我正在尝试在驱动器上调用OneDrive API的搜索 endpoints (即 https://graph.microsoft.com/v1.0/drives/{drive-id}/root/search(q='mysearchterm')
. 这在Graph Explorer上工作正常,但是,我没有在同一驱动器上获得客户端凭据流的任何搜索结果 .
我的应用程序注册具有API文档中提到的所有必需的应用程序权限( Files.Read.All
, Files.ReadWrite.All
, Sites.Read.All
, Sites.ReadWrite.All
),并且读取驱动器,driveitems,下载驱动器项目都可以正常工作 . 一件事不起作用的是搜索驱动器项目 . 我只是得到一个空阵列,没有错误;
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)","value":[]}
我正在使用 adal-node 和 acquireTokenWithClientCredentials
.
var adal = require("adal-node");
const TENANT = "{tenant-name-here}.onmicrosoft.com";
const CLIENT_ID = "{Application-id-here}";
const CLIENT_SECRET = "{Application-key-here}";
function getToken() {
return new Promise((resolve, reject) => {
const authContext = new adal.AuthenticationContext(
`https://login.microsoftonline.com/${TENANT}`
);
authContext.acquireTokenWithClientCredentials(
GRAPH_URL,
CLIENT_ID,
CLIENT_SECRET,
(err, tokenRes) => {
if (err) {
reject(err);
}
resolve(tokenRes.accessToken);
}
);
});
}
我正在搜索的驱动器是一个SharePoint文档库 .
1 回答
Some important tip :客户端凭据流需要在Azure Management Portal中注册应用程序,但不能在Applicaation Registeration Portal中注册 . Graph Explorer主要基于后者,所以他们现在有不同的后端代码是正常的 . 也许他们会在未来做同样的逻辑 .
adal-node与Graph不同,因此您可以在graph explorer中获得结果,但不能获得NodeJS产品 . 我们建议您使用最新的Graph API .
官方文件:https://docs.microsoft.com/en-us/javascript/api/overview/azure/activedirectory?view=azure-node-latest