I've accepted some work using SharePoint. I need to discover the APIs and call them. I've looked for examples and followed one that looks like this:
var siteUrl = "https://contoso.sharepoint.com";
var username = "user@contoso.onmicrosoft.com";
var password = "pass@word1";
var securePassword = new SecureString();
password.ToCharArray().ToList().ForEach(c => securePassword.AppendChar(c));
var credentials = new SharePointOnlineCredentials(username, password);
var handler = new HttpClientHandler();
handler.Credentials = credentials;
var uri = new Uri(siteUrl);
handler.CookieContainer.SetCookies(uri, credentials.GetAuthenticationCookie(uri));
var json = string.Empty;
using (var client = new HttpClient(handler))
{
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose");
var response = await client.GetAsync(siteUrl + "/_api/Web");
response.EnsureSuccessStatusCode();
json = await response.Content.ReadAsStringAsync();
}
I've got these libraries installed: sigh I pasted an image into SO and it does not work
Microsoft.Sharepoint.Client
Microsoft.Sharepoint.Client.Runtime
TICUE.NetCore.SharepointOnline.CSOM.16......
I note all doco says the first two would work and they did not. The last one gave me the class at all.
However, I still get an error that I can finally see the SharePointOnlineCredentials class, but the IDE insists that GetAuthenticationCookie is not a method. Pretty much every online instruction I've found did not work, does Sharepoint API just change constantly? Is there a real source of truth? The Microsoft docs I found say this method exists.
I created a DLL outside Maui in case it was a Maui issue but my core code is in a Maui project.