简体   繁体   English

从Office365的sharePoint在线计数未读消息

[英]sharePoint online count unread message from office365

As part of a project whose aim is to notably improve the visual side of a SharePoint Online site, I'm a bit stuck. 作为该项目的一部分,该项目的目的是显着改善SharePoint Online网站的视觉效果,我有些困惑。 On the home page in the left banner, users want to see the number of unread messages they have in Office365. 在左侧横幅的主页上,用户希望查看他们在Office365中拥有的未读邮件数。

I created an area in the master page to put the result in. I thought the Rest API used to do this : 我在母版页中创建了一个区域来放入结果。我以为Rest API用于执行此操作:

$.ajax ({
    type: "GET",
    url: " https://outlook.office365.com/ews/odata/Me/Folders/Inbox",
    dataType : "json",
    success : function (resp) {
        // count unread messages 
    },
    error : function (e) {
        alert (' Error121212 :' + JSON.stringify (e));
    }
 })

Unfortunately I get an error like cross domain. 不幸的是,我收到跨域之类的错误。 I tried with JSONP but it does not work either (uncaught syntax error unexpected token). 我尝试使用JSONP,但也不起作用(未捕获的语法错误意外令牌)。

Can you please tell me if this is a good practice? 您能告诉我这是否是一种好习惯吗? I feel that it anyways I must find a technic for authentication. 无论如何,我觉得我必须找到一种认证技术。 (In the case of JSONP I have a popup that asks me authentication and then problem occurs on callback apparently)... (在JSONP的情况下,我有一个弹出窗口要求我进行身份验证,然后显然在回调上发生问题)...

I want to avoid developing a type requiring a typical deployment Wsp... 我想避免开发一种需要典型部署Wsp的类型。

Thank you in advance for your help. 预先感谢您的帮助。

Your URL for the ajax request seems incorrect. 您的Ajax请求网址似乎不正确。 The URL for getting the inbox messages via the API is: https://outlook.office365.com/api/v1.0/me/folders/inbox/messages 通过API获取收件箱消息的URL为: https://outlook.office365.com/api/v1.0/me/folders/inbox/messages : https://outlook.office365.com/api/v1.0/me/folders/inbox/messages

Once you get the response, you can count the number of objects with the IsRead property set to false using a simple for loop and display that count. 获得响应后,可以使用简单的for循环对IsRead属性设置为false的对象数进行计数并显示该计数。

The issue here is related to CORS and how browsers refuse to handle cross-domain requests. 这里的问题与CORS以及浏览器如何拒绝处理跨域请求有关。 To get around this, typically you would either 为了解决这个问题,通常您会

  • Change the response header on the remote server - not an option here 更改远程服务器上的响应标头-此处不是一个选项
  • Use some sort of proxy to handle the requests - here's where SharePoint apps come in. 使用某种代理来处理请求-这是SharePoint应用程序出现的地方。

I know you stipulated that you want to avoid using a WSP style deployment but there simply isn't a way around it, you have to use the SharePoint App Model 我知道您已规定要避免使用WSP样式部署,但是根本无法解决,您必须使用SharePoint App Model

This article goes a long way to answer your question, but for completion the basic steps are as follows 条走一段很长的方式来回答你的问题,但对于完成基本步骤如下

  1. Create a SharePoint hosted app in Visual Studio 在Visual Studio中创建SharePoint托管的应用程序
  2. In the App Manifest, you need to define the trust relationship with the remote host (in this case the host of outlook.office365.com) using the AppManifest section 在App Manifest中,您需要使用AppManifest部分定义与远程主机(在本例中为outlook.office365.com主机)的信任关系。

  3. Use SP.RequestExecutor.executor to make the request on your behalf 使用SP.RequestExecutor.executor代表您发出请求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM