本文介绍了如何将事件写入活动连接outlook日历上的特定日历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在探索Live Connect SDK。



我可以使用 Microsoft创建日历和读取活动,甚至创建新活动。



我创建了一个日历,表示



但是我的所有尝试都无法将事件链接到新创建的日历,例如 [编程日历] code>。



因此,我正在阅读SDK文档,发现以下内容:

我的创建代码是:

 私有异步任务editEvent()
{
if (!connected)
{
try
{
var authClient = new LiveAuthClient();
LiveLoginResult result = await authClient.LoginAsync(new string [] {wl.signin,wl.calendars,wl.calendars_update});
//\"wl.skydrive,wl.skydrive_update,
if(result.Status == LiveConnectSessionStatus.Connected)
{
var eventToPost = new Dictionary< string,object> ();
eventToPost.Add(name,my new event);

eventToPost.Add(calendar_id,calendar.136c10ca65544801.99c35f9a9fb341a3af35daa82f4569f8);

eventToPost.Add(description,this should be 2nd calendar);
eventToPost.Add(start_time,2014-09-10T01:30:00-08:00);
eventToPost.Add(end_time,2014-09-12T03:00:00-08:00);
eventToPost.Add(location,business placeeeeeee);
eventToPost.Add(is_all_day_event,false);
eventToPost.Add(availability,busy);
eventToPost.Add(visibility,public);

this.session = result.Session;
connected = true;
this.connectClient = new LiveConnectClient(result.Session);
var meResult = await connectClient.PostAsync(me / events,eventToPost);

meData = meResult.Result;

}
}
catch(LiveAuthException ex)
{
infoTextBlock.Text + = ex.Data +.autexception ..+ ex。信息;
//显示错误消息。
}
catch(LiveConnectException ex)
{
infoTextBlock.Text + = ex.Data +.conExcception ..+ ex.Message;
//显示错误消息。
}
}

}

更新的代码为:

 私有异步任务editEvent()
{
if b $ b {
try
{
var authClient = new LiveAuthClient();
LiveLoginResult result = await authClient.LoginAsync(new string [] {wl.signin,wl.calendars,wl.calendars_update});

if(result.Status == LiveConnectSessionStatus.Connected)
{
var eventToPost = new Dictionary< string,object>();
eventToPost.Add(name,program my c# - 2nd trial);

eventToPost.Add(calendar_id,calendar.136c10ca65544801.99c35f9a9fb341a3af35daa82f4569f8);

eventToPost.Add(description,this should be 2nd calendar);
eventToPost.Add(start_time,2014-09-10T01:30:00-08:00);
eventToPost.Add(end_time,2014-09-12T03:00:00-08:00);
eventToPost.Add(location,business placeeeeeee);
eventToPost.Add(is_all_day_event,false);
eventToPost.Add(availability,busy);
eventToPost.Add(visibility,public);

this.session = result.Session;

connected = true;
this.connectClient = new LiveConnectClient(result.Session);

var meResult = await connectClient.PutAsync(event.136c10ca6a355671.5f21a7994c7e40fd800bc48dcc07300b.991d1912ec6b4523a0f08839992aa2bb,eventToPost);

meData = meResult.Result;
}
}
catch(LiveAuthException ex)
{
//显示错误消息。
}
catch(LiveConnectException ex)
{
//显示错误消息。
infoTextBlock.Text + = ex.Data +...+ ex.Message;
}
}
}

将永远不会更改日历ID属性,它将使用默认日历ID。



因此,研究


I'm exploring the Live Connect SDK.

I can create calendar and read events, and even create new events using the Microsoft.Live library.

After I created a calendar say [Programming calendar] I wanted to write an event to it.

However all my attempts have failed to link the event to the newly created calendar i.e. [Programming calendar].

So I was reading the SDK documentations and found the following:

My code for creation was:

private async Task editEvent()
{
    if (!connected)
    {
 try
                {
                    var authClient = new LiveAuthClient();
                    LiveLoginResult result = await authClient.LoginAsync(new string[] { "wl.signin", "wl.calendars", "wl.calendars_update" });
                    //"wl.skydrive, wl.skydrive_update",
                    if (result.Status == LiveConnectSessionStatus.Connected)
                    {
                        var eventToPost = new Dictionary<string, object>();
                     eventToPost.Add("name", "my new event");

                     eventToPost.Add("calendar_id", "calendar.136c10ca65544801.99c35f9a9fb341a3af35daa82f4569f8");

                     eventToPost.Add("description", "this should be 2nd calendar");
                     eventToPost.Add("start_time", "2014-09-10T01:30:00-08:00");
                     eventToPost.Add("end_time", "2014-09-12T03:00:00-08:00");
                     eventToPost.Add("location", "business placeeeeeee");
                     eventToPost.Add("is_all_day_event", false);
                     eventToPost.Add("availability", "busy");
                     eventToPost.Add("visibility", "public");

                        this.session = result.Session;
                        connected = true;
                        this.connectClient = new LiveConnectClient(result.Session);
                        var meResult = await connectClient.PostAsync("me/events", eventToPost);

                        meData = meResult.Result;

                    }
                }
                catch (LiveAuthException ex)
                {
                    infoTextBlock.Text += ex.Data + " .autexception.." + ex.Message;
                    // Display an error message.
                }
                catch (LiveConnectException ex)
                {
                    infoTextBlock.Text += ex.Data + " .conExcception.." + ex.Message;
                    // Display an error message.
                }
}

}

and my code for update was:

private async Task editEvent()
{
    if (!connected)
    {
        try
        {
            var authClient = new LiveAuthClient();
            LiveLoginResult result = await authClient.LoginAsync(new string[] { "wl.signin", "wl.calendars", "wl.calendars_update" });

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                var eventToPost = new Dictionary<string, object>();
                eventToPost.Add("name", "program my c# - 2nd trial");

                eventToPost.Add("calendar_id", "calendar.136c10ca65544801.99c35f9a9fb341a3af35daa82f4569f8");

                eventToPost.Add("description", "this should be 2nd calendar");
                eventToPost.Add("start_time", "2014-09-10T01:30:00-08:00");
                eventToPost.Add("end_time", "2014-09-12T03:00:00-08:00");
                eventToPost.Add("location", "business placeeeeeee");
                eventToPost.Add("is_all_day_event", false);
                eventToPost.Add("availability", "busy");
                eventToPost.Add("visibility", "public");

                this.session = result.Session;

                connected = true;
                this.connectClient = new LiveConnectClient(result.Session);

                var meResult = await connectClient.PutAsync("event.136c10ca6a355671.5f21a7994c7e40fd800bc48dcc07300b.991d1912ec6b4523a0f08839992aa2bb", eventToPost);

                meData = meResult.Result;
            }
        }
        catch (LiveAuthException ex)
        {
            // Display an error message.
        }
        catch (LiveConnectException ex)
        {
            // Display an error message.
            infoTextBlock.Text += ex.Data + " ..." + ex.Message;
        }
    }
}

It works fine except that it will never change the calendar ID property and it will use the default calendar ID.

So researching the documentations on the REST reference I found the following fact !!

so there is a discrepancy in the documentations bec. the table says the calendar_id is readonlyand they claims that you can write to any calendar using the correct scope " Use wl.calendars_update to create Event objects on any of the user's calendars "

One more things I confirmed that in my newly created calendar [Programming calendar] the permission property I am the owner !

So what am I missing here?

解决方案

Ok I discovered where i was wrong:

//this line is useless since the property is readOnly

eventToPost.Add("calendar_id", "calendar.136c10ca65544801.99c35f9a9fb341a3af35daa82f4569f8");

//this is the wrong line [ wrong path]

var meResult = await connectClient.PostAsync("me/events", eventToPost);

//this is the correct way [proper path use]i.e. replace "me" by "CALENDAR_ID"

var meResult = await connectClient.PostAsync("calendar.136c10ca65544801.99c35f9a9fb341a3af35daa82f4569f8/events", eventToPost);

referrence for this solution :http://social.msdn.microsoft.com/Forums/windowsapps/en-US/15207829-4999-46d9-a835-e350526f3aa

这篇关于如何将事件写入活动连接outlook日历上的特定日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 19:00