Click here to Skip to main content
15,888,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on a requirement,to create a windows service which sends calendar invites to ivitees for the scheduled meetings from the admin email address, for which mail server is hosted on office365. I have created a Azure app and able to get access token, and when I tried to read the calendar events form the rest service,a Internal sever exception happed".
Follwing is the code snippet I tried.Can you please help me/refer me to the resources ,for acheiving my requirement.

C#
authContext = new AuthenticationContext(authority);
clientCredential = new ClientCredential(clientId, appKey);



AuthenticationResult result = null;
int retryCount = 0;
bool retry = false;
string header = "";

do
{
    retry = false;
    try
    {
        
        result = authContext.AcquireToken(todoListResourceId, clientCredential);
        header = result.CreateAuthorizationHeader();
    }
    catch (AdalException ex)
    {
        if (ex.ErrorCode == "temporarily_unavailable")
        {
            retry = true;
            retryCount++;
            Thread.Sleep(3000);
        }

        Console.WriteLine(
            String.Format("An error occurred while acquiring a token\nTime: {0}\nError: {1}\nRetry: {2}\n",
            DateTime.Now.ToString(),
            ex.ToString(),
            retry.ToString()));
    }

} while ((retry == true) && (retryCount < 3));

if (result == null)
{
    Console.WriteLine("Canceling attempt to contact To Do list service.\n");
    return;
}



var url = "https://outlook.office365.com/api/v2.0/me/calendarview?startDateTime=2014-10-01T01:00:00Z&endDateTime=2015-12-31T23:00:00Z";
var request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "GET";
request.ContentType = "application/json";
var oAuthHeader = header;
request.Headers.Add("Authorization", oAuthHeader);
var response = request.GetResponse();
Posted
Updated 3-Jan-16 19:10pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900