繁体   English   中英

Outlook Rest API不返回任何结果

[英]Outlook Rest API returning no results

我正在尝试使用Microsoft在此处的示例请求显示Outlook日历中的事件列表

但是,我之前没有使用任何种类的REST API的适当经验。 使用他们提供的URL,我应该可以找回一些东西,但是我没有。 这是我的控制器中的代码:

  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();

然后在我看来,我这样称呼ViewBags

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

但是,除了我here ,并end我什么也没得到。 这是一个没有我自己输入的项目,所以我必须在网络上做所有的事情,这就是为什么我使用了很多try catches

可以给我一些使用REST API的经验吗?

我在您的代码中看不到任何身份验证,因此可能返回401。您需要使用OAuth2来获取访问令牌,并使用该令牌来对您的呼叫进行身份验证。 由于您是在C#中执行此操作,因此您可能希望查看NuGet上的API包装器,这些包装器为您实现了很多功能。 http://dev.office.com/code-samples上有一些示例入门应用程序可能也有帮助(搜索ASP.NET MVC)。

暂无
暂无

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

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