API 365 REST API call from .net console application

Please note that this question does not concern the general call of the REST service. Its about the specific Office 365 REST API.

To be specific, I need to use the API here: https://msdn.microsoft.com/office/office365/APi/contacts-rest-operations#UsingtheContactsRESTAPI

I was wondering how Office 365 REST services can be used in the Console application . There are tools for working with APIs from web applications, mobile applications and applications for Windows stores. But I did not find a resource for the console application.

I have an application created on the application registration portal here: https://apps.dev.microsoft.com

So, I already have an Id application, Application Secrets, Platforms Mobile application (client identifier, redirect URI)

I think I need an authentication token (I have a username, password). And use this to call REST services.

+4
source share
1 answer

Currently, two versions are supported for the Office 365 Mail, Calendar, and Contacts APIs: v1andv2

About REST API v2

Office 365 API Azure Active Directory (Azure AD) Office 365. Azure AD OAuth 2.0.

API- Office 365, Azure AD.


API v1, Basic, , , :

class Program
{
    static void Main(string[] args)
    {

        ReadContacts().Wait();
    }

    private static async Task ReadContacts()
    {
        var handler = new HttpClientHandler();
        handler.Credentials = new NetworkCredential()
        {
            UserName = ConfigurationManager.AppSettings["UserName"],
            Password = ConfigurationManager.AppSettings["Password"]
        };

        using (var client = new HttpClient(handler))
        {
            var url = "https://outlook.office365.com/api/v1.0/me/contacts";
            var result = await client.GetStringAsync(url);

            var data = JObject.Parse(result);

            foreach (var item in data["value"])
            {
                Console.WriteLine(item["DisplayName"]);
            }
        }
    }
}
+3

Source: https://habr.com/ru/post/1623758/


All Articles