【问题标题】:https://graph.microsoft.com/v1.0/me is giving 404https://graph.microsoft.com/v1.0/me 给 404
【发布时间】:2020-07-30 17:38:18
【问题描述】:

我正在尝试从https://graph.microsoft.com/v1.0/me 获取当前用户。

我得到了一个有效的令牌,但是,对https://graph.microsoft.com/v1.0/me 的请求给了我一个 404。

var token;
$(document).ready(function () {
    requestToken();
});

function requestToken() {
    $.ajax({
        "async": true,
        "crossDomain": true,
        "url": "https://cors-anywhere.herokuapp.com/https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token",
        "method": "POST",
        "headers": {
            "content-type": "application/x-www-form-urlencoded"
        },
        "data": {
            "grant_type": "client_credentials",
            "client_id ": "{client_id}",
            "client_secret": "{client_secret}",
            "scope ": "https://graph.microsoft.com/.default"
        },
        success: function (response) {
            console.log(response);
            token = response.access_token;
            getUserInformation();
        },
        error: function (error) {
            console.log(JSON.stringify(error));
        }
    })
}

function getUserInformation() {
    $.ajax({
        method: 'GET',
        url: "https://graph.microsoft.com/v1.0/me",
        headers: {
            'Authorization': 'Bearer ' + token,
            'Content-Type': 'application/json'
        },
    }).success(function(response) {
        console.log(response);
    }).error(function(error) {});
}

有人知道可能是什么问题吗?

谢谢。

【问题讨论】:

    标签: javascript graph http-status-code-404


    【解决方案1】:

    我得到了详细的回复: “错误”: { "code": "Request_ResourceNotFound", "message": "资源 '' 不存在或其查询的引用属性对象之一不存在。", “内部错误”:{ “请求ID”:“”, “日期”:“2020-04-17T09:33:43” } } }

    【讨论】:

      【解决方案2】:

      来自https://graph.microsoft.com/v1.0/me

      我明白了:

      {
      
          "error": {
      
              "code": "InvalidAuthenticationToken",
      
              "message": "Access token is empty.",
      
              "innerError": {
      
                  "date": "2020-10-20T11:39:50",
      
                  "request-id": "becb1443-91e3-42d9-9c77-b9808aaf2cf7",
      
                  "client-request-id": "becb1443-91e3-42d9-9c77-b9808aaf2cf7"
      
              }
      
          }
      
      }
      

      https://graph.microsoft.com/.default

      {
      
          "error": {
      
              "code": "BadRequest",
      
              "message": "Invalid version.",
      
              "innerError": {
      
                  "date": "2020-10-20T11:41:04",
      
                  "request-id": "3fdd24bd-7c96-4ff2-9e18-fc042673ecd2",
      
                  "client-request-id": "3fdd24bd-7c96-4ff2-9e18-fc042673ecd2"
      
              }
      
          }
      
      }
      

      【讨论】:

        【解决方案3】:

        通常,当路由不存在时,请求会返回 404 状态码,所以我建议您检查提供的 URI 是否有效。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-09-14
          • 2021-01-11
          • 2020-12-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多