Я хочу создать событие в календаре встреч. Я добавил пользователя в объявление Azure, а также назначил делегированное разрешение Calendars.ReadWrite.
Но при создании события по следующим строкам выдается ошибка:
var response = await graphClient.Me.Calendar.Events.Request().AddAsync(@event);
Код: MailboxNotEnabledForRESTAPI Сообщение: Почтовый ящик либо неактивен, либо обратимо удален, либо размещен локально. .
public async Task CreateAppointmentAsync()
{
var spinId = Guid.NewGuid();
StringBuilder apptBody = new StringBuilder();
var httpClient = new System.Net.Http.HttpClient();
System.Net.Http.HttpResponseMessage response;
bool success = false;
var username = _employee.Email;
var employee = _employeeService.GetEmployeeByEmail(username);
var employeeaccess = employee.EmployeeOfficeToken;
string token = employeeaccess;
//bool isTokenValid = IsTokenExpired(token);
//if (isTokenValid)
//{
// MessageBox.Show("Access token is still valid.");
//}
if (token == null || token.Length < 10)
{
var dialogResult = MessageBox.Show($"You do not has a security token for this function, Would you like to get one?", "Get Leads - No Security Token",
MessageBoxButton.YesNo);
if (dialogResult == MessageBoxResult.Yes)
{
_eventAggregator.GetEvent().Publish(new FireToCbInfo("Shell", null, "GetToken"));
}
return success;
}
// Start Spinner
var spinner = new SetupSpinner(_eventAggregator, _container, _logMessage, spinId.ToString(), "Creating Appointment");
try
{
var graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("bearer", token);
return System.Threading.Tasks.Task.CompletedTask;
}));
Event evt = new Event();
// Because my variable is a reserved word in the api, I have to poke it into something different before using it
var localLocation = Location;
// Body
const string newLine = "
";
apptBody.Append("Email: " + SelectedEstimator.Email);
apptBody.Append(newLine);
apptBody.Append(EditCustomer.Notes);
ItemBody body = new ItemBody();
body.Content = apptBody.ToString();
body.ContentType = Microsoft.Graph.BodyType.Html;
var email = new Microsoft.Graph.EmailAddress
{
Address = SelectedEstimator.Email
};
email.Address = SelectedEstimator.Email;
var recipient = new Recipient();
recipient.EmailAddress = email;
evt.Organizer = recipient;
evt.IsOrganizer = true;
evt.IsDraft = false;
// Event General Information
evt.Subject = Title;
evt.Body = body;
evt.Location = new Microsoft.Graph.Location
{
DisplayName = localLocation
};
// load up date and times
// Start
DateTimeTimeZone dtStart = new DateTimeTimeZone();
dtStart.TimeZone = TimeZoneInfo.Local.Id;
string dts = AppointmentDate.ToString("o");
dtStart.DateTime = dts;
// End
DateTimeTimeZone dtEnd = new DateTimeTimeZone();
dtEnd.TimeZone = TimeZoneInfo.Local.Id;
string dte = AppointmentDate.AddHours(1).ToString("o");
dtEnd.DateTime = dte;
evt.Start = dtStart;
evt.End = dtEnd;
// Reminder off
evt.IsReminderOn = false;
// Create Event
//var createdEvent = await graphClient.Me.Events.Request().AddAsync(evt);
var createdEvent = await graphClient.Me.Calendar.Events.Request().AddAsync(evt);
success = true;
if (success)
MessageBox.Show("Appointment Created!!");
return success;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return success;
}
finally
{
// Stop spinner
Thread.Sleep(100);
_eventAggregator.GetEvent().Publish(spinId.ToString());
}
}
Подробнее здесь: https://stackoverflow.com/questions/776 ... soft-delet
Как исправить ошибки Microsoft Graph API. Почтовый ящик либо неактивен, либо обратимо удален, либо размещен локально при ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Не могу читать почтовый ящик с Gmail API - access_token_scope_insuffilet
Anonymous » » в форуме JAVA - 0 Ответы
- 9 Просмотры
-
Последнее сообщение Anonymous
-