I have a console app written in C#. I need to get some of the information from a SharePoint site. This instance of SharePoint is part of Office 365 (i.e. SharePoint Online).
My challenge is, I can't use the helper library. I have to use the REST-based APIs since I'm using .NET Core.
To begin, I registered my console app with Azure Active Directory. This console app is created in the same Azure Active Directory that my Office 365 environment is part of. I've also granted the "Read items in all site collections" delegated permission for the "Office 365 SharePoint Online" API to my console app.
In my situation, I have a console app sitting on a server. I've set up a test user with a username/password on my SharePoint tenant. I also have the Client ID for the console app I registered with Azure Active Directory and a Redirect URL.
At this time, I have some code that looks like this:
var accessToken = await GetToken(); // retrieves a token from Active Directory
using(var client = new HttpClient()) {
client
.DefaultRequestHeaders
.Clear();
client
.DefaultRequestHeaders
.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
client
.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var apiUrl = "https://[mySite].sharepoint.com/_api/web";
// how do I get the title of the site at the apiUrl variable?
}
I feel like I'm close since I'm getting an access token. I just can't seem to figure out how to get the title of the site. How do I get the title of a SharePoint Site from my C# code?