gpt4 book ai didi

javascript - O365 中的 Request_BadRequest

转载 作者:行者123 更新时间:2023-12-02 22:56:42 25 4
gpt4 key购买 nike

我正在尝试在 O365 的帮助下发送电子邮件。我已经配置了所有内容,但出现错误

GraphError { statusCode: 405, code: 'Request_BadRequest',
message: 'Specified HTTP method is not allowed for the request target.', requestId: '34f321-57de-4483-b97d-5957f8786ecb', date: 2019-09-16T00:17:53.000Z, body: '{"code":"Request_BadRequest","message":"Specified HTTP method is not allowed for the request target.","innerError":{"request-id":"34f803b1-57de-4483-b97d-5957f8786ecb","date":"2019-09-16T05:47:51"}}' }

代码

const APP_ID = "XXXXXXXXXXXXXXXXXX";
const APP_SECERET = "XXXXXXXXXXXXXX";
const TENANT_ID = "XXXXXXXXXXXXXXXX";
const TOKEN_ENDPOINT = "https://login.microsoftonline.com/XXXXXXXXXXXXXXXXXXXXX/oauth2/v2.0/token";
const MS_GRAPH_SCOPE = "https://graph.microsoft.com/.default";
const GRANT_TYPE = "client_credentials";
const graphScopes = ["User.Read", "Mail.Send"]; // An array of graph scopes

const request = require("request");
const endpoint = TOKEN_ENDPOINT;
const requestParams = {
grant_type: GRANT_TYPE,
client_id: APP_ID,
client_secret: APP_SECERET,
scope: MS_GRAPH_SCOPE
};
request.post({
url: endpoint,
form: requestParams
}, function(err, response, body) {
if (err) {
console.log("error");
} else {
// console.log(response);
// console.log("Body=" + body);
let parsedBody = JSON.parse(body);
if (parsedBody.error_description) {
console.log("Error=" + parsedBody.error_description);
} else {
console.log("Access Token=" + parsedBody.access_token);
// testGraphAPI(parsedBody.access_token);
let accessToken = parsedBody.access_token;
getMe(accessToken);
}
}
});

function getMe(accessToken) {
require("isomorphic-fetch");
const fs = require("fs");
const MicrosoftGraph = require("@microsoft/microsoft-graph-client").Client;
const options = {
defaultVersion: "v1.0",
debugLogging: true,
authProvider: (done) => {
done(null, accessToken);
},
};

// https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/samples/node/main.js
// https://learn.microsoft.com/en-us/graph/overview

const client = MicrosoftGraph.init(options);

// send an email
const sendMail = {
message: {
subject: "Test o365 api from node",
body: {
contentType: "Text",
content: "Testing api."
},
toRecipients: [{
emailAddress: {
address: "test@abc.com"
}
}],
ccRecipients: [{
emailAddress: {
address: "test@abc.com"
}
}]
},
saveToSentItems: "false"
};

client.api('/users/test1@abc.onmicrosoft.com ').post(sendMail).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
}

有人可以告诉我哪里出了问题吗?请帮帮我

最佳答案

我遇到了同样的错误,发送给用户时这是一个格式错误的网址。

我认为您的网址应该是 /users/test1@abc.onmicrosoft.com/sendMail

关于javascript - O365 中的 Request_BadRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57951047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com