我一直致力于订阅,以便在收到电子邮件时通知我的应用程序。为了激活订阅,我向https://graph.microsoft.com/v1.0/subscriptions
. 每当我发送请求时,我都会收到以下错误(请注意,从 Graph Explorer 尝试时,这工作正常):
response => {
"error"=> {
"code"=>"InvalidRequest",
"message"=>"Server could not process subscription creation payload.",
"innerError"=> {
"request-id"=>"e4a9aef5-89b0-4d9c-ac11-01e0c188ceee",
"date"=>"2019-11-07T13:15:50"
}}}
代码示例:
GRAPH_HOST = 'https://graph.microsoft.com'.freeze
def mail_noti token
query = {
"changeType": "created,updated",
"notificationUrl": "https://0d9fdb76.ngrok.io/calendar/notif_sub",
"resource": "me/mailFolders('Inbox')/messages",
"clientState": "secretClientValue",
"expirationDateTime": "2019-11-08T18:23:45.9356913Z",
"Authorization": "Bearer #{token}",
"Accept": 'application/json'
}
headers = {
Authorization: "Bearer #{token}",
Accept: 'application/json'
}
endpoint = '/v1.0/subscriptions'
binding.pry
a = HTTParty.post("#{GRAPH_HOST}#{endpoint}", body: query, headers: headers)
end