调用 Outlook API 以使用 ajax 调用将事件添加到 outlook 日历

Calling Outlook API to Add event to outlook calendar using ajax call

我需要将我的数据库中的一个事件添加到 outlook 日历中,为此我一直在尝试 ajax 调用 outlook auth API 首先看起来像这样

$scope.authorizeOutlook = function () {

    let redirect = 'http://localhost:51419';
    let clientId = 'xxx';

    var authData = 'client_id=' + clientId + '&response_type=code&redirect_uri=' + redirect + '&response_mode=query&scope=https%3A%2F%2Fgraph.microsoft.com%2Fcalendars.readwrite%20&state=12345';
    debugger
    $.ajax({
        url: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
        type: 'POST',
        host: 'https://login.microsoftonline.com',
        contentType: "application/x-www-form-urlencoded",
        contentLength: "600",
        data: authData,
        success: function (response) {
            debugger;
            alert(response.status);
            //alert("success");
        },
        error: function (response) {
            alert(response.status);
            //alert("fail");
        }
    });
}

但是我收到的响应状态为 0。这是什么意思?我哪里做错了?

如果使用Oauth2.0,需要添加"token-type: Bearer"

参考资料来自:

Get access tokens to call Microsoft Graph