【问题标题】:Bad Request - personal onedrive account - https://graph.microsoft.com/v1.0/me/drive/root/children错误请求 - 个人 onedrive 帐户 - https://graph.microsoft.com/v1.0/me/drive/root/children
【发布时间】:2019-12-19 23:51:13
【问题描述】:

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

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

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

个人账户的重定向网址是 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-...

【问题讨论】:

    标签: office365 microsoft-graph-api onedrive


    【解决方案1】:

    如果您想将 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/

    【讨论】:

    • 使用添加了 /v2.0 的新端点,我可以成功验证并获取文件。非常感谢您的帮助!
    猜你喜欢
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-09-14
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多