I'm trying to obtain the content of an image stored in a SharePoint Online list column using the GraphServiceClient
instance but, I'm receiving an Unauthorized error.
My code is the following:
// Creating the GET request with the right URL to the image
var message = new HttpRequestMessage(HttpMethod.Get, imageFields.ServerUrl + imageFields.ServerRelativeUrl);
// Waiting for authenticating the request (seems this is not working as expected)
await this._graphService.AuthenticationProvider.AuthenticateRequestAsync(message);
// Requesting data
var response = await this._graphService.HttpProvider.SendAsync(message);
// Retrieving the image content
var content = await response.Content.ReadAsByteArrayAsync();
Let me say that the this._graphService
variable is created fine, because, previous to this code, I'm doing a request to obtain the imageFields
properties from SharePoint Online with success.
I saw that I have to authenticate the request with the AuthenticationProvider
property but, for any unknown reason, it is not working as I expect.
Let me share the way I create the _graphService
object to make everything more clear:
public GraphServiceClient Create() {
var clientSecretCredential = new ClientSecretCredential(
this._configuration.TenantId,
this._configuration.ClientId,
this._configuration.ClientSecret
);
return new GraphServiceClient(clientSecretCredential, this._configuration.Scopes);
}
So, do you know if I can use and how to use a GraphServiceClient
instance to make HTTP requests (probably using the HttpProvider
property) to retrieve SharePoint Online images stored in a SharePoint Online list in an image column?