在.net应用程序中获取我的谷歌日历的所有事件

时间:2014-11-20 06:21:25

标签: asp.net google-calendar-api

当我尝试将应用程序中的事件添加到Google日历时,我收到以下错误。

我的代码如下: - '

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Net;
using System.Web.UI.WebControls;
using Google.GData.Calendar;
using Google.GData.Extensions;
using Google.GData.AccessControl;
using Google.GData.Client;
public partial class Calender : System.Web.UI.Page
{
   public static Uri oCalendarUri;
    protected void Page_Load(object sender, EventArgs e)
    {
        //eventEntry();
        try{
            string sGoogleUserName = "xxxxxxxxx@gmail.com";
            string sGooglePassword = "xxxxxxxx";
            Uri oCalendarUri = new Uri("http://www.google.com/calendar/feeds/" + sGoogleUserName + "/private/full");

            //Initialize Calendar Service
            CalendarService oCalendarService = new CalendarService("API Project");
            oCalendarService.setUserCredentials(sGoogleUserName, sGooglePassword);

            //Use Proxy 
            //GDataRequestFactory oRequestFactory = (GDataRequestFactory)oCalendarService.RequestFactory;
            //WebProxy oWebProxy = new WebProxy(WebRequest.DefaultWebProxy.GetProxy(oCalendarUri));
            //oWebProxy.Credentials = CredentialCache.DefaultCredentials;
            //oWebProxy.UseDefaultCredentials = true;
            //oRequestFactory.Proxy = oWebProxy;


            //Set Event Entry 
            Google.GData.Calendar.EventEntry oEventEntry = new Google.GData.Calendar.EventEntry();
            oEventEntry.Title.Text = "Test Calendar Entry From .Net";
            oEventEntry.Content.Content = "Hurrah!!! I posted my first Google calendar event through .Net";

            //Set Event Location 
            Where oEventLocation = new Where();
            oEventLocation.ValueString = "New Zealand";
            oEventEntry.Locations.Add(oEventLocation);

            //Set Event Time
            When oEventTime = new When(new DateTime(2011, 5, 31, 9, 0, 0), new DateTime(2011, 5, 31, 9, 0, 0).AddHours(1));
            oEventEntry.Times.Add(oEventTime);

            //Set Additional Properties
            ExtendedProperty oExtendedProperty = new ExtendedProperty();
            oExtendedProperty.Name = "SynchronizationID";
            oExtendedProperty.Value = Guid.NewGuid().ToString();
            oEventEntry.ExtensionElements.Add(oExtendedProperty);

            // CalendarService oCalendarService = GAuthenticate();

            //Prevents This Error
            //{"The remote server returned an error: (417) Expectation failed."}
            System.Net.ServicePointManager.Expect100Continue = false;

            //Save Event
            oCalendarService.Insert(oCalendarUri, oEventEntry);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }`

得到错误:'执行请求失败:https://www.google.com/calendar/feeds/xxxxxxxxx@gmail.com/private/full'

1 个答案:

答案 0 :(得分:0)

我使用谷歌Api v3解决了这个问题。现在我的申请工作正常。