简体   繁体   English

Outlook Rest API不返回任何结果

[英]Outlook Rest API returning no results

I'm trying to display a list of events from an Outlook calendar using the example request microsoft have here 我正在尝试使用Microsoft在此处的示例请求显示Outlook日历中的事件列表

However, I've no proper experience with using any sort of REST APIs before. 但是,我之前没有使用任何种类的REST API的适当经验。 Using the URL they provide I should be getting something back but I'm not. 使用他们提供的URL,我应该可以找回一些东西,但是我没有。 Here is the code in my controller: 这是我的控制器中的代码:

  string uri = "https://outlook.office365.com/api/v1.0/me/events";

    var webRequest = (HttpWebRequest)WebRequest.Create(uri);
    webRequest.Method = "GET";
    string result = "";
    try
    {
        WebClient webClient = new WebClient();
        webClient.Encoding = Encoding.UTF8;
        result = webClient.DownloadString(uri);
        try
        {
            string returnedString = result;
            TempData.Add("myval", result);
            ViewBag.result = "returned string " + result;

        }
        catch (Exception er2)
        {
            ViewBag.error = er2.Message;
        }

        ViewBag.secondresult = "first result " + result;
    }
    catch (Exception er)
    {


    }

    ViewBag.firstResult = "Outside try catch " + result;
    ViewBag.url = uri;
    return View();

Then in my view I'm calling the ViewBags like this: 然后在我看来,我这样称呼ViewBags

<p> here </p>
@ViewBag.url
@ViewBag.firstResult                        
@ViewBag.result
@ViewBag.error
@ViewBag.secondresult
<p> end </p>

But besides my here and end I get nothing. 但是,除了我here ,并end我什么也没得到。 This is a project that was set up without any input from myself so I'm having to do everything across a network which is why I'm using so many try catches . 这是一个没有我自己输入的项目,所以我必须在网络上做所有的事情,这就是为什么我使用了很多try catches

Can someone with more experience with using REST APIs tell me if I'm messing something up somewhere? 可以给我一些使用REST API的经验吗?

I don't see any authentication in your code, so it's likely returning a 401. You need to use OAuth2 to get an access token and use that to authenticate your calls. 我在您的代码中看不到任何身份验证,因此可能返回401。您需要使用OAuth2来获取访问令牌,并使用该令牌来对您的呼叫进行身份验证。 Since you're doing this in C#, you might want to look at the API wrappers on NuGet that implement a lot of this for you. 由于您是在C#中执行此操作,因此您可能希望查看NuGet上的API包装器,这些包装器为您实现了很多功能。 There are some sample starter apps on http://dev.office.com/code-samples that might be helpful too (search for ASP.NET MVC). http://dev.office.com/code-samples上有一些示例入门应用程序可能也有帮助(搜索ASP.NET MVC)。

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

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