Many people have the experience of using the Calendar,it does facilitate our works and lifes.But most of the Calendars are based on text alert, that means you can only get the reminder event in front of your computer.
So I think if the Calendar can remind me by phone.If I want to achieve this idea, I need a Calendar that can provide me APIs, a technology that can make me to call through programming.
Fortunately,these technologies for this idea have been provided ,Google Calendar and IVR(Interactive Voice Response, based on phone call).
I've posted some articles to introduce IVR.You can view them here:
IVR used in Voicent Gateway
IVR used in Facebook
Or, you can investigate it throught the Google Search,there are lots of article to introduce it.Now, we'll mainly concentrate on the Google Calendar.
Google Calendar allows client applications to view and update
calendar events in the form of Google data API ("GData") feeds. Your
client application can use the Google Calendar data API to create new
events, edit or delete existing events, and query for events that match
particular criteria.
There are many possible uses for
the Calendar data API. For example, you can create a web front end for
your group's calendar that uses Google Calendar as a back end. Or you
can generate a public calendar for Google Calendar to display, based on
your organization's event database. Or you can search relevant
calendars to display a list of upcoming events on those calendars.
You can view these articles to comprehend the Google Calendar:
What are the Google Data APIs?
Google Data APIs Client Libraries
Google Data APIs Samples
Developer's Guide
These articles provide detailed introductions and examples for using the .NET Client Library to work with the Google Calendar service. For help setting up the client library, see the Getting Started Guide.
You will find examples of adding events, updating events, deleting
events and querying events. If you're interested in understanding more
about the underlying protocol used by the .NET Client Library to
interact with the Calendar data API, please see the protocol tab.
After you read those,you can continue the following topics.
How to create Calendar Service
The CalendarService
class represents a client connection (with authentication) to a Calendar
service. To request a feed using the .NET
client library, first instantiate a new CalendarService
object and authenticate the user. Then use the Query
method to retrieve a
CalendarFeed
object that contains entries for all of the user's
calendars.
You can authenticate the user by WebForm or WinForm,the WebForm is called
AuthSub proxy authentication, and the WinForm is called ClientLogin username/password authentication.
In order to authenticate the applications using the AuthSub login protocol,you must get the Session token.
First,construct a AuthSubRequest URL for your application, make a .NET client library call as follows:
AuthSubUtil.getRequestUrl("http://www.example.com/RetrieveToken",
"http://www.google.com/calendar/feeds/",
false,
true);
The getRequestUrl
method takes several parameters :
- "next" URL ,which is the URL
that Google will redirect to after the user logs into their account and
grants access;
- scope ,as determined in the previous section;
- two Booleans, one to indicate whether the token will be used in
registered mode or not, and one to indicate whether the token will
later be exchanged for a session token or not.
The above example shows
a call in unregistered mode (the first Boolean is false
), for a token that will be exchanged for a session token later (the second Boolean is true
); adjust the Booleans appropriately for your application.
After
the user follows the link to the AuthSub page at Google and logs in,
the AuthSub system then redirects the user back to your application,
using the "next" URL you provided.
When Google redirects
back to your application, the token is appended to the "next" URL as a
query parameter. So in the case of the above "next" URL, after the user
logs in, Google redirects to a URL like http:
. Therefore, the token is accessible as a variable in the ASP page's Request.QueryString
object.
The
token you initially retrieve is always a one-time use token. You can
exchange this token for a session token using the AuthSubSessionToken
URL, as described in the AuthSub documentation. Your application can make this exchange using the .NET client library as follows:
Session["sessionToken"] =
AuthSubUtil.exchangeForSessionToken(Request.QueryString["token"], null);
Now
you are ready to use the session token to authenticate requests to the
Calendar server by placing the token in the Authorization header.
GAuthSubRequestFactory authFactory =
new GAuthSubRequestFactory("cl", "CalendarSampleApp");
authFactory.Token = Session["sessionToken"].ToString();
Service service = new Service("cl", authFactory.ApplicationName);
service.RequestFactory = authFactory;
To use ClientLogin, invoke the setUserCredentials
method of CalendarService
, specifying the ID and password of the user on whose behalf your client is sending the query. For example:
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("jo@gmail.com", "mypassword");
You can get a list of a user's calendars by sending an authenticated GET
request to the allcalendars feed URL:
http:
You also can query to retrieve a list of calendars that the authentiated user has access to:
http:
After instantiate a new CalendarService
object and authenticate the user, then use the Query
method to retrieve a CalendarFeed
object that contains entries for all of the user's calendars.
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("jo@gmail.com", "mypassword");
CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("http://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed resultFeed = service.Query(query);
Console.WriteLine("Your calendars:\n");
foreach (CalendarEntry entry in resultFeed.Entries)
{
Console.WriteLine(entry.Title.Text + "\n");
}
The CalendarService the key to get the services of Google Calendar,when you finish this,you can get what you want.In the next topic,I will follow that way to get the StartTime of a Calendar Event,and call user using the IVR.
Call user when the event rises up
My idea is first I do a callback to the server side from the client using JavaScript. In the server side, using CalendarService query to retrive the StartTime of the EventEntry from the Calendar Service. Then return the time string to the client, in the client, using the JavaScript method setTimeout to circularly check the returned time with the client time. When they are equal,go back to the server side,construct a IVR object to call user.
This is the html code:
<head id="Head1" runat="server">
<title>GetGoogleEvent</title>
<script language="javascript" type="text/javascript">
var stopTimmer;
var strReturn;
function ReceiveDateFromServer(valueReturnFromServer)
{
document.getElementById("ServerTime").innerHTML = "DateTime of Server:"
+ valueReturnFromServer;
strReturn = valueReturnFromServer;
TriggerEvent();
}
function GetServerTime(format)
{
CallBackToServer(format, "");
}
function TriggerEvent()
{
var localDate = Date.parse((new Date()).toString("en-US"));
document.getElementById('NowTime').innerHTML = "DateTime of Now:"
+ (new Date()).toString("en-US");
var serverDate = Date.parse(strReturn);
var diff = localDate - serverDate;
if (diff >= 0)
{
clearTimeout(stopTimmer);
var btnCall = document.getElementById('btnCall');
if (btnCall != null)
{
btnCall.click();
}
return false;
}
stopTimmer = setTimeout("TriggerEvent()", 1000);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnStartReminder" runat="server" Text="Start Reminder"
OnClientClick="javascript:GetServerTime('');return false;" />
<br />
<br />
<span id="ServerTime">
DateTime of Now<%= DateTime.Now.ToString("yyyy-MM-dd HHHH:mm:ss") %>
</span>
<br />
<span id="NowTime"></span>
<div style="display:none">
<asp:Button ID="btnCall" runat="server" onclick="CallUser" Text="Button" />
</div>
</div>
</form>
</body>
This is the codebehind:
You'll need the following using
statements:
using System.Globalization;
using Google.GData.AccessControl;
using Google.GData.Calendar;
using Google.GData.Client;
using Google.GData.Extensions;
In order to do callback,your class must inherit from the ICallbackEventHandler
interface.
public partial class CalendarEvent : System.Web.UI.Page, ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strRefrence = Page.ClientScript.GetCallbackEventReference(
this,
"callArgs",
"ReceiveDateFromServer",
"callContext");
string strCallBack = "function CallBackToServer(callArgs, callContext) {"
+ strRefrence + "};";
Page.ClientScript.RegisterClientScriptBlock(
this.GetType(),
"CallBackToServer",
strCallBack,
true);
}
private string eventMessage = String.Empty;
public string GetCallbackResult()
{
DateTimeFormatInfo myDTFormatInfo =
new CultureInfo("en-US", false).DateTimeFormat;
DateTime eventStartTime = DateTime.Now;
CalendarService calService =
new CalendarService("GoogleCalendarAndIVRSampleApp");
calService.setUserCredentials("userid@gmail.com", "password");
string feedUri =
"http://www.google.com/calendar/feeds/userid@gmail.com/private/full";
Google.GData.Calendar.EventQuery eventQuery =
new Google.GData.Calendar.EventQuery(feedUri);
eventQuery.Query = "NewEvent of mine";
EventFeed resultEventFeed = calService.Query(eventQuery);
Google.GData.Calendar.EventEntry myEventEntry =
(Google.GData.Calendar.EventEntry)resultEventFeed.Entries[0];
eventStartTime = myEventEntry.Times[0].StartTime;
eventMessage = myEventEntry.Summary.Text;
return eventStartTime.ToString("F", myDTFormatInfo);
}
public void RaiseCallbackEvent(string eventArgument)
{
}
protected void CallUser(object sender, EventArgs e)
{
VoicentIVR callUserByIVR = new VoicentIVR("localhost", 1982);
callUserByIVR.CallText("User's phone", eventMessage, true);
}
}
The class VoicentIVR is contained in the solution in the ZIP file for downloaded.
Btw,my environment is VS2008,but I don't use the features of .NET Framework 3.5, so I guess these codes can also work fine in VS2005.
Points of Interest
IVR,Google Calendar,Skype
History
IVR introduce
IVR Starter