Я бьюсь головой о стену уже 2 дня.
Я проверил, все настройки Azure и разрешения API установлены правильно. Вот код, который у меня есть на данный момент.
Код: Выделить всё
using Azure.Identity;
using Microsoft.Graph;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Microsoft.Graph.Models;
using Microsoft.Identity.Client;
using static System.Formats.Asn1.AsnWriter;
namespace PopulateCalendar
{
internal class Program
{
static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json")
.Build();
var credentials = new ClientSecretCredential
(
config["GraphCalendar:TenantId"],
config["GraphCalendar:ClientId"],
config["GraphCalendar:ClientSecret"],
new TokenCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud }
);
string OrganizerEmail = "purchasing@cantonfoodco.com";
GraphServiceClient graphServiceClient = new GraphServiceClient(credentials);
var requestBody = new Event
{
Subject = "Event Subject",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "What the event is about",
},
Start = new DateTimeTimeZone
{
DateTime = "2024-11-29T10:00:00",
TimeZone = "Pacific Standard Time",
},
End = new DateTimeTimeZone
{
DateTime = "2024-11-29T14:00:00",
TimeZone = "Pacific Standard Time",
},
Location = new Location
{
DisplayName = "Location of Event",
},
TransactionId = "7E163156-7762-4BEB-A1C6-729EA81755A7",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var calendars = graphServiceClient.Users[config["GraphCalendar:UserObjectId"]]
.Calendars["AQMkAGEzZDM0OTY5LWMzMjgtNGIxMy05ZWQ4LWM0MzZmYjY3NwA0YzUARgAAA4FoDJtpplFKsFjbsbk87SMHAPRwDiDSU_BCkOt4FQfkqmQAAAIBBgAAAPRwDiDSU_BCkOt4FQfkqmQAAAITCgAAAA=="]
.Events
.PostAsync(requestBody);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... ng-happens
Мобильная версия