Node.js Can';t使用Azure应用程序访问一个驱动器直通图API
我指的是使用Azure应用程序通过图形API访问一个驱动器。我正在使用以下node.js代码获取Microsoft Graph API的访问令牌:Node.js Can';t使用Azure应用程序访问一个驱动器直通图API,node.js,azure,microsoft-graph-api,onedrive,Node.js,Azure,Microsoft Graph Api,Onedrive,我指的是使用Azure应用程序通过图形API访问一个驱动器。我正在使用以下node.js代码获取Microsoft Graph API的访问令牌: const axios = require('axios'); const qs = require('qs'); const postData = { client_id: client_id from azure app, scope: 'https://graph.microsoft.com/.default', client_secr
const axios = require('axios');
const qs = require('qs');
const postData = {
client_id: client_id from azure app,
scope: 'https://graph.microsoft.com/.default',
client_secret: app_secret from azure app
grant_type: 'client_credentials'
};
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
try{
let res = await axios.post('https://login.microsoftonline.com/{tenant from azure app}/oauth2/v2.0/token', qs.stringify(postData));
console.log(res.data);
}catch (e) {
console.log(e.message);
}
上述代码返回以下响应:
{
token_type: 'Bearer',
expires_in: 3599,
ext_expires_in: 3599,
access_token: 'value of access token'
}
{
"error": {
"code": "BadRequest",
"message": "Unable to retrieve user's mysite URL.",
"innerError": {
"date": "2020-07-02T14:08:36",
"request-id": "67ef24fa-XXXX-XXXX-853a-XXXXXXXXXXXX"
}
}
}
在完成上述步骤之前,一切正常。我从上述响应中获取访问令牌,并尝试执行以下graph API来访问一个驱动器:
let config = { headers:
{'Authorization': "Bearer "+ res.data.access_token} # Obtain access token from the above response
};
let res_drive = await axios.get("https://graph.microsoft.com/v1.0/me/drive/sharedWithMe", config);
但是,上面的graph API调用返回以下响应:
{
token_type: 'Bearer',
expires_in: 3599,
ext_expires_in: 3599,
access_token: 'value of access token'
}
{
"error": {
"code": "BadRequest",
"message": "Unable to retrieve user's mysite URL.",
"innerError": {
"date": "2020-07-02T14:08:36",
"request-id": "67ef24fa-XXXX-XXXX-853a-XXXXXXXXXXXX"
}
}
}
我还设置了使用Azure应用程序访问graph API的权限,如下所示:
如果我遗漏了什么,请告诉我
如何使用Azure应用程序访问一个drive-through graph API?在您的示例中获取令牌的方式对应于(应用程序权限)。此流中没有可用的
me
上下文(它只是已登录用户的别名),因为此流中不存在已登录用户,这就是首先发生所提供错误的原因
要在此流中调用共享文件
端点,用户需要:
谢谢你的解决方案。您知道如何访问与组织共享的驱动器文件夹吗?我试过
https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/drive/sharedWithMe
但我找不到该文件夹。有什么提示吗?不确定,sharedWithMe
endpoint应该随文件一起返回文件夹面。您是否确定它没有被返回,或者您的查询返回了几个页面?建议提出另一个问题并提供一些详细信息?使用sharedWithMe
endpoint,我可以看到共享文件,但这些文件在我的组织内。在我的组织之外,我在此终结点中看不到任何文件。我还发现GitHub上有一个与此相关的问题。