I’m successfully using the ‘Get New Access Token’ button in Postman. I’m using the returned token, to create a calendar event outlook.com . Now, I’m trying to do the same thing in C#. What I started with was to create a header key/value pair for each item on the ‘Get New Access Token’ dialog box in Postman. My code is below. I’m currently getting a (403) Forbidden error. Any help would be greatly appreciated.
string lstrEndPoint = @“https://outlook.office.com/api/v2.0/me/events”;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(lstrEndPoint);
request.Method = “GET”;
request.Accept = “application/json”;
request.Credentials = new NetworkCredential(“myemail”, “mypassword”);
request.UserAgent = “Test”;
request.Headers.Add(“Grant-Type”, “Authorization Code”);
request.Headers.Add(“Callback-URL”, “https://outlook.live.com/calendar/0/view/month”);
request.Headers.Add(“Auth-URL”, “url obtained from Azure Active Directory admin center”);
request.Headers.Add(“Access-Token-URL”, “url obtained from Azure Active Directory admin center”);
request.Headers.Add(“Client-ID”, “string obtained from Azure Active Directory admin center”);
request.Headers.Add(“Client-Secret”, “string obtained from Azure Active Directory admin center”);
request.Headers.Add(“Scope”, “https://outlook.office.com/calendars.readwrite”);
request.Headers.Add(“State”, “State”);
request.Headers.Add(“Client-Authentication”, “Send as Basic Auth header”);
HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();