错误请求 - 个人 onedrive 帐户 - https://graph.microsoft.com/v1.0/me/drive/root/children

Bad Request - personal onedrive account - https://graph.microsoft.com/v1.0/me/drive/root/children

我正在编写一个 window 的应用程序来从个人和工作 onedrive 帐户下载文件。

同样的请求适用于工作帐户,但不适用于个人帐户。

不确定这是否与设置有关。

个人账户的重定向 url 是 login.live.com/oauth20_desktop.srf.

身份验证通过:login.microsoftonline.com/common/oauth2/

请求个人和工作帐户:

requestMessage = {Method: GET, RequestUri: 'https://graph.microsoft.com/v1.0/me/drive/root/children?pretty=false', Version: 1.1, Content: <null>, Headers:
{
  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFEUk5ZUlEzZGhSU3JtLTRLLWFkcENKVm1pX2Fvb1NzcThPZ1g...

个人账户回复:

httpResponse = {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Transfer-Encoding: chunked
  request-id: 843007b8-ebe4-4c9c-b260-d2a92512b672
  client-request-id: 843007b8-ebe4-4c9c-b260-d2a92512b672
  ...

来自工作帐户的回复:

httpResponse = {StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Transfer-Encoding: chunked
  Vary: Accept-Encoding
  request-id: a27688cb-fc5f-4e8c-8a9b-7a3ce1e4c98c
  client-request-id: a27688cb-fc5f-4e8c-8a9b-...

如果要将 Microsoft Graph 与个人和企业 OneDrive 结合使用,则需要使用 Azure Active Directory OAuth v2 端点

https://login.microsoftonline.com/common/oauth/v2.0/authorize
https://login.microsoftonline.com/common/oauth/v2.0/token

这些将确定用户是个人帐户还是工作帐户,然后获取 Microsoft Graph 可以使用的访问令牌。

有关此的更多详细信息:https://azure.microsoft.com/en-us/documentation/articles/active-directory-v2-protocols-oauth-code/