当前位置: 首页 > 知识库问答 >
问题:

通过Microsoft Graph API订阅消息,无需用户交互

梁丘波
2023-03-14

我正在尝试创建一个应用程序,该应用程序使用Microsoft Graph API在Office 365中订阅邮件事件(新邮件,创建,更新),而无需用户交互。如果有新电子邮件,我想向使用 C# MVC5 和 .Net 4.5 构建的应用发送通知。我下面的一个例子是在Github中(使用Daemon Service Github项目链接),但它是在.Net Core中构建的。我遇到了另一个使用 Web 作业的应用程序,它非常接近我的要求
Azure 网络作业,但它在过去 2 年中没有更新。我按照步骤操作,但其中大多数与我的 Azure 开发人员帐户(免费)不匹配。有人可以帮我吗?

应用程序设置:

应用程序设置:

<add key="tenantId" value="[Tenant_ID]" />
    <add key="clientId" value="[AppID]" />
    <add key="clientSecret" value="[Client Secret]" />
    <add key="webjobs" value="DefaultEndpointsProtocol=https;AccountName=onvidawebjob1aa1b;AccountKey=Z3xewALbEc43gE/dL06HxCGIjVtpaiTkIY4ZolkjZt9Z86xHIZLzMwXBlujNI8/PcTJbM1LIs5KNceVTGgESmA==" />
    <add key="subscriptionblobname" value="subscriptions/subscription1" />
    <add key="notificationurl" value="https://onvidawebjob1.azurewebsites.net/api/HttpTrigger1?code=H7liZOlcQc5qjcZOkRXEb0x4JVqTzoXnrl6mAswsEKl4LlmAYm/ACw==" />

我尝试重新创建应用程序,但出现以下问题跟踪

Development settings applied
Found the following functions:
WebHooksSample.Functions.ManageSubscriptions
WebHooksSample.Functions.OnNotificationReceived
Singleton lock acquired (cd016b3464fa4d8aa8f41f884a064168/WebHooksSample.Functions.ManageSubscriptions.Listener)
Function 'WebHooksSample.Functions.ManageSubscriptions' is configured to run on startup. Executing now.
Executing 'Functions.ManageSubscriptions' (Reason='Timer fired at 2018-11-16T19:05:27.4182054+05:30', Id=155f7f8a-c352-427f-a7c3-a55ab3518c9a)
Exception while executing function: Functions.ManageSubscriptions
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ManageSubscriptions ---> System.Net.Http.HttpR
equestException: Response status code does not indicate success: 400 (Bad Request).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at WebHooksSample.Functions.<ManageSubscriptions>d__14.MoveNext() in D:\354132\office365_sample_app\webjobs\webjobs-webhooks-sample-master\WebHooks
Sample\Functions.cs:line 128
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.<InvokeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<InvokeAsync>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithWatchersAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext()
   --- End of inner exception stack trace ---
Exception while executing function: Functions.ManageSubscriptions
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ManageSubscriptions ---> System.Net.Http.HttpR
equestException: Response status code does not indicate success: 400 (Bad Request).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at WebHooksSample.Functions.<ManageSubscriptions>d__14.MoveNext() in D:\354132\office365_sample_app\webjobs\webjobs-webhooks-sample-master\WebHooks
Sample\Functions.cs:line 128
--- End of stack trace from previous location where exception was thrown ---

--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.<InvokeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<InvokeAsync>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithWatchersAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at `enter code here`System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext()
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__10.MoveNext()
The next 5 occurrences of the schedule will be:
11/16/2018 7:06:03 PM
11/16/2018 7:06:33 PM
11/16/2018 7:07:03 PM
11/16/2018 7:07:33 PM
11/16/2018 7:08:03 PM
Job host started
Executing 'Functions.ManageSubscriptions' (Reason='Timer fired at 2018-11-16T19:05:57.4122054+05:30', Id=405fe97b-2b8a-48bb-a761-7c46a293622c)
Exception while executing function: Functions.ManageSubscriptions
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ManageSubscriptions ---> System.Net.Http.HttpR
equestException: Response status code does not indicate success: 400 (Bad Request).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at WebHooksSample.Functions.<ManageSubscriptions>d__14.MoveNext() in D:\354132\office365_sample_app\webjobs\webjobs-webhooks-sample-master\WebHooks
Sample\Functions.cs:line

编辑1:

我能够使用outlook connector和office 365 webhook API(使用azure logic应用程序中可用的默认连接器)完成接收电子邮件(无需用户登录),类似于这里描述的内容。但是,outlook connector每隔x秒(由我设置的自定义值)html" target="_blank">轮询一次邮箱中的任何更改,但是我希望该服务在不轮询的情况下自动触发Webhook事件。如果我理解正确的话,应该是这样的——

> < li>

创建注册的webhook以监视事件

创建一个使用以上webhook的outlook connector。

Outlook connector在工作流中通知应用程序(REST API调用)。

共有1个答案

房新翰
2023-03-14

以下是需要考虑的一些要点:

> < li>

无论您使用何种语言/平台,使用Microsoft Graph webhook通知都是一样的。唯一的区别是您如何/在哪里托管您的通知endpoint。

要在没有用户交互的情况下订阅通知,您的应用需要仅限应用的权限

您可能想了解Azure函数;它们为Microsoft GFIG提供了一些易于使用的绑定:https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-microsoft-graph

 类似资料:
  • 主要内容:一、通知,二、源码分析,三、总结一、通知 在Redis中,既可以实现消息的发送又可以实现订阅,也就是常说的发布/订阅。它的主要逻辑实现在nofigy.c和module.c、pubsub.c中,其实通知做为一种辅助功能,是易用性的一种良好的接口。Redis的通知功能是一种即时在线通知功能,如果CS端断线后,相关的消息就无法再次通知,也就是说,消息机制没有保存和重发功能。这也是为了实现设计上的简单和功能实现的鲁棒性的考虑,至于以后会

  • 微信文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.addTemplate.html 组合模板并添加至帐号下的个人模板库 $tid = 563; // 模板标题 id,可通过接口获取,也可登录小程序后台查看获取 $kidLi

  • 开普勒消息目前分为三大类:公告,告警和通知。 通知中根据不同的操作事件类型,分为十几个事件。每个事件都跟项目操作相关。便于接收项目操作变更的通知。 分类 事件 公告 Alarm 告警 Proclaim 通知 Build,Apply,Audit,Delete,Rollback,Logging,Reboot,Command,Storage,Extend... 订阅界面: 用户中心,点击头像,下拉菜单→

  • 1.手机版 设置方法:订阅号右上角详情-在消息中置顶   2.电脑版 设置方法:订阅号右上角详情-设置-在消息中置顶

  • 我有一个超时选项,只想在超时前接收消息。 如果您能解释下面的代码是如何工作的,以及我如何修改下面的代码以在特定的时间框架内接收消息,并且一旦我的超时已经到达就停止接收,这将是很有帮助的。

  • 问题内容: 我正在使用Paho发送和接收mqtt消息。到目前为止,发送消息一直没有问题,我正在使用mosquitto接收消息。 现在,我想使用Java客户端读取消息,并且注意到关于接收消息的文档越来越少。 我实现了MqttCallback接口,但仍然无法弄清楚如何阅读已订阅的主题的消息。 到目前为止,这是我的源代码,我可以使用mosquitto_sub读取消息。 问题答案: 您将在代理有时间将消息