I am trying to access a sharepoint online site using the Office 365 APIs mentioned here I am getting the auth token and calling the discovery service as below:
httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
httpClient.DefaultRequestHeaders.Add("Accept", "application/json; odata=verbose");
response = await httpClient.GetAsync(new Uri("https: / /api.office.com/discovery/me/services"));
data = await response.Content.ReadAsStringAsync();
I get the following types of endpoint URLs in the result:
OneDrive
https: / / sometenant-my.sharepoint.com/personal/sometenant_data_onmicrosoft_com/_apiOutlook related
https: / /outlook.office365.com/api/v1.0
I don't get any endpoint URLs for SharePoint in the results. If I try the below code:
httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
httpClient.DefaultRequestHeaders.Add("Accept", "application/json; odata=verbose");
response = await httpClient.GetAsync("https://sometenant.sharepoint.com/_api/web/lists/getByTitle('Documents')/items");
data = await response.Content.ReadAsStringAsync();
I get the following in the response stream:
"{\"error\":\"invalid_client\",\"error_description\":\"Invalid audience Uri 'Microsoft.SharePoint'.\"}"
The error in the response is:
{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
x-ms-diagnostics: 3000003;reason="Invalid audience Uri 'Microsoft.SharePoint'.";category="invalid_client"
SPRequestGuid: 8462cf9c-c093-1000-a3da-fc5e1aab16c1
request-id: 8462cf9c-c093-1000-a3da-fc5e1aab16c1
SPRequestDuration: 37
SPIisLatency: 25
MicrosoftSharePointTeamServices: 16.0.0.3431
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
Date: Mon, 24 Nov 2014 22:45:46 GMT
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
Server: Microsoft-IIS/7.5
WWW-Authenticate: Bearer realm="xxxxxx-xxxx-xxxxx-xxxx-xxxxxxxx",client_id="xxxxxxxx-xxx-xxxx-xxxx-000000000000",trusted_issuers="xxxxxxx-xxxx-xxx-xxx-000000000000@*,https : // sts.windows.net/*/,00000003-0000-xxxxx-ce00-000000000000@xxxxxxxx-xxxxx-11e1-xxxx-xxxxxxx",authorization_uri="https://login.windows.net/common/oauth2/authorize"
X-Powered-By: ASP.NET
Content-Length: 93
}}
I believe I should be able to access SharePoint data using the Office 365 APIs.
I have give app full control on all site collection permissions.
Please advise if I am missing anything here.