Hi @Valentin Maschenko ,
Please ensure that you have assigned necessary license to access M365 resources.
Hope this helps.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Currently I'm trying to create user activity from uwp application. But every time I encounter this response.
{
"error": {
"code": "AuthenticationError",
"message": "Error authenticating with resource",
"innerError": {
"date": "2022-12-28T09:20:16",
"request-id": "some id",
"client-request-id": "some id"
}
}
}
Here is my c# code example. Request json content string was taken from Microsoft Learn
public sealed class UserActivityProvider : IUserActivityProvider
{
private const string activityId = "SendMessageUserActivity";
private static HttpClient httpClient = new HttpClient();
public UserActivityProvider()
{
}
private async Task<string> GetAccessTokenAsync(Account account)
{
var accessToken = string.Empty;
var publicClientApplication = PublicClientApplicationBuilder.Create(MicrosoftConstants.ClientId)
.WithRedirectUri(MicrosoftConstants.RedirectUri)
.Build();
var scopes = new string[]
{
"UserActivity.ReadWrite.CreatedByApp"
};
AuthenticationResult? authToken = null;
try
{
authToken = await publicClientApplication.AcquireTokenSilent(scopes, account.Email).ExecuteAsync();
}
catch (Exception)
{
authToken = await publicClientApplication.AcquireTokenInteractive(scopes).ExecuteAsync();
}
if (authToken != null)
{
accessToken = authToken.AccessToken;
}
return accessToken;
}
public async Task CreateUserActivityAsync(Account account, CreatingMessageUserActivityParameters userActivityParameters)
{
var accessToken = await GetAccessTokenAsync(account);
if (accessToken != string.Empty)
{
var contentForCreatingActivity = new StringContent(json, Encoding.UTF8, "application/json");
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
var response = await httpClient.PutAsync($"https://graph.microsoft.com/beta/me/activities/{activityId}", contentForCreatingActivity);
var stringifiedResponse = await response.Content.ReadAsStringAsync();
}
}
}
And here is also get method for retrieving all activities and it's also return bad request
public async Task<string?> IsUserActivityExistsAsync(Account account)
{
string? resultSubject = null;
var accessToken = await GetAccessTokenAsync(account);
if (accessToken != string.Empty)
{
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
var response = await httpClient.GetAsync("https://graph.microsoft.com/v1.0/me/activities");
var stringifiedResponse = await response.Content.ReadAsStringAsync();
}
return resultSubject;
}
All articles referencing that I have to provide correct scope but I took that scope from official Microsoft Learn and there wouldn't be a mistake.
Hi @Valentin Maschenko ,
Please ensure that you have assigned necessary license to access M365 resources.
Hope this helps.