https://graph.microsoft.com/v1.0/me提供404

时间:2020-04-17 09:09:11

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

我正在尝试从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) {});
}

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

谢谢。

3 个答案:

答案 0 :(得分:0)

我得到了详细的答复: “错误”:{ “ code”:“ Request_ResourceNotFound”, “ message”:“资源”不存在,或者其查询的参考属性对象之一不存在。“, “ innerError”:{ “ request-id”:“”, “ date”:“ 2020-04-17T09:33:43” } } }

答案 1 :(得分:0)

来自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"

        }

    }

}

答案 2 :(得分:-1)

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