使用访问令牌在Google日历中插入数据

时间:2014-09-26 09:50:16

标签: google-api google-calendar-api access-token

关注Google oAuth -1。我通过Client_ID& amp; Secret_ID -2。交换该代码以获取访问令牌 -3。现在我要插入删除&搜索数据/事件在Google日历中使用我可用的访问令牌而不是用户凭据。请告诉我我做错了什么。

  

获取错误:   执行请求失败:http://www.google.com/calendar/feeds/imenmyself4u@gmail.com/private/full

有人可以帮忙吗?

 Uri oCalendarUri;
ExtendedProperty oExtendedProperty;

 void Insert() 
{
    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";


    Where oEventLocation = new Where();
    oEventLocation.ValueString = "New Zealand";
    oEventEntry.Locations.Add(oEventLocation);

    When oEventTime = new When(new DateTime(2014, 9, 26, 09, 0, 0),
 new DateTime(2014, 9, 26, 12 , 0, 0).AddHours(2));
    oEventEntry.Times.Add(oEventTime);

    oExtendedProperty = new ExtendedProperty();
    oExtendedProperty.Name = "SynchronizationID";
    oExtendedProperty.Value = Guid.NewGuid().ToString();
    myValue = oExtendedProperty.Value;
    oEventEntry.ExtensionElements.Add(oExtendedProperty);

    CalendarService oCalendarService = GAuthenticate();
    System.Net.ServicePointManager.Expect100Continue = false;

    //Save Event        
    oCalendarService.Insert(oCalendarUri, oEventEntry);  
}

 private CalendarService GAuthenticate()
{

    oCalendarUri = new Uri("http://www.google.com/calendar/feeds/" +
                               sGoogleUserName + "/private/full");

    CalendarService oCalendarService = new CalendarService("CalendarSampleApp");
    string token = Session["token"].ToString();        
    oCalendarService.SetAuthenticationToken(token);

    return oCalendarService;
}

1 个答案:

答案 0 :(得分:0)

您正在使用的API已被弃用,并将于今年11月关闭(https://developers.google.com/google-apps/calendar/v2/developers_guide_protocol)。请将代码更新为最新的API,您可以在此处找到迁移指南:https://developers.google.com/google-apps/calendar/migration