无需身份验证即可获取office365电子邮件的日历

时间:2016-05-08 23:39:23

标签: c# asp.net json office365

我想获得特定用户的活动列表,请发送使用office365帐户的user@company1.com,user @ company2.com。

我需要在不登录时重新访问user@company2.com日历。我的应用程序就像为我的客户列出我的可用时间,以便他们可以选择我的空闲时间并安排与我会面。我需要从列表中过滤已经安排的事件......是否有任何示例代码可以在没有登录的情况下获取日历事件?

我尝试了Office365多租户应用程序,该应用程序将仅在登录后提供用于获取日历事件的示例代码。我需要它没有身份验证。请帮帮我。

2 个答案:

答案 0 :(得分:1)

无法在不进行身份验证的情况下尝试访问O365信息,无论是用户身份验证还是应用身份验证都需要。在您的方案中,您可能需要应用身份验证。您可以尝试使用客户端凭据授权流程来构建守护程序或服务应用程序,如此blog中所述,该服务应用程序需要管理员同意,但有权访问Office 365租户中的任何邮箱/日历信息。

另一种选择是使用EWS托管API,您可以使用EWS托管API获取用户的忙/闲信息和建议的会议时间:

https://msdn.microsoft.com/en-us/library/office/dn643673(v=exchg.150).aspx

Outlook上现有的Office加载项支持:

https://findtime.microsoft.com/

答案 1 :(得分:0)

最后我尝试使用忙/闲代码。我的代码如下......我正在遵循这个程序,但我不知道它是否正确。我有一个Microsoft Office 365帐户,并通过静默传递凭据,我正在创建Exchange Server服务。之后,我将不同的域参与者信息作为ORGANIZER传递,并且如下所示。但它返回的所有值都没有为这些用户跳过任何预定的会议。

假设 user1@domain.com 是ORGANIZER,并且需要 user2@anotherdomain.com 进行会议。 User1每天下午7:00-7:30安排会议,但是当我执行以下脚本时,它会在7:00-7:30pm显示我可用于会议。它应该阻止那段时间。

您能否建议对代码进行一些更改,我是否以正确的方式进行操作?

private static void GetSuggestedMeetingTimes(ExchangeService service)
{


    List<AttendeeInfo> attendees = new List<AttendeeInfo>();

    attendees.Add(new AttendeeInfo()
    {
        SmtpAddress = "user1@mydomain.com",
        AttendeeType = MeetingAttendeeType.Organizer
    });

    attendees.Add(new AttendeeInfo()
    {
        SmtpAddress = "user2@anotherdomain.com",
        AttendeeType = MeetingAttendeeType.Required
    });

    // Specify options to request free/busy information and suggested meeting times.
    AvailabilityOptions availabilityOptions = new AvailabilityOptions();
    availabilityOptions.GoodSuggestionThreshold = 49;
    availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
    availabilityOptions.MaximumSuggestionsPerDay = 40;
    // Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
    availabilityOptions.MeetingDuration = 30;
    availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
    availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
    availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

    // Return free/busy information and a set of suggested meeting times. 
    // This method results in a GetUserAvailabilityRequest call to EWS.
    GetUserAvailabilityResults results = service.GetUserAvailability(attendees,
                                                                     availabilityOptions.DetailedSuggestionsWindow,
                                                                     AvailabilityData.FreeBusyAndSuggestions,
                                                                     availabilityOptions);
    // Display suggested meeting times. 
    Console.WriteLine("Availability for {0} and {1}", attendees[0].SmtpAddress, attendees[1].SmtpAddress);
    Console.WriteLine();

    foreach (Suggestion suggestion in results.Suggestions)
    {
        Console.WriteLine("Suggested date: {0}\n", suggestion.Date.ToShortDateString());
        Console.WriteLine("Suggested meeting times:\n");
        foreach (TimeSuggestion timeSuggestion in suggestion.TimeSuggestions)
        {
            Console.WriteLine("\t{0} - {1}\n",
                              timeSuggestion.MeetingTime.ToShortTimeString(),
                              timeSuggestion.MeetingTime.Add(TimeSpan.FromMinutes(availabilityOptions.MeetingDuration)).ToShortTimeString());



        }
    }

    int i = 0;

    // Display free/busy times.
    foreach (AttendeeAvailability availability in results.AttendeesAvailability)
    {
        Console.WriteLine("Availability information for {0}:\n", attendees[i].SmtpAddress);

        foreach (CalendarEvent calEvent in availability.CalendarEvents)
        {
            Console.WriteLine("\tBusy from {0} to {1} \n", calEvent.StartTime.ToString(), calEvent.EndTime.ToString());
        }

        i++;
    }