Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Using Google's Data API in Brew: An Introduction : Page 2

Add functionality to your Brew applications with IWEB and Google's powerful Calendar API.


advertisement
Retrieving a Public Feed
The first, and possibly simplest, way you’ll interact with the Google calendar API is to retrieve an XML feed for a public calendar. It's a great place to start because it involves one (sometimes two) simple HTTP get requests and no cookies or tokens. First, make sure the calendar you want to access is public. Once that's done, you should be able to access it through this simple function:

static void GetCalendarStream(void *pData) { GApp *pme = (GApp*)pData; char *szPostHeader; ISourceUtil *pUtil; IPeek *ppeek; ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_WEB, (void **)&pme->pEventWeb); CALLBACK_Init(&pme->clb, CalCallback, pme); szPostHeader = MALLOC(200); SPRINTF(szPostHeader, "Content-Type:application/atom+xml\r\n"); IWEB_GetResponse(pme->pEventWeb,(pme->pEventWeb, &pme->pResp, &pme->clb, "http://www.google.com/calendar/feeds/joe@gmail.com/public/full", WEBOPT_HEADER, szPostHeader, WEBOPT_METHOD, "GET", WEBOPT_HANDLERDATA, pme, WEBOPT_HEADERHANDLER, EventHeader, WEBOPT_COPYOPTS, TRUE, WEBOPT_END)); FREE(szPostHeader); }

This is a fairly straightforward example of an IWEB GetResponse call. You'll need to set the content type in the headers by hand. Google specs out the feed URL as follows:

"http://www.google.com/calendar/feeds/*email-address*/*access-level*/*feed-level*"

In the previous example, you can see that you've looked up a non-existent joe@gmail.com account. This example requests only public events (hence the "public" access level) and full details on all those events. To read calendars that have not been made public, you'll have to log in. You'll see more on that later.



Now that you've requested all this data, how do you receive it? The easiest thing to do is write it to a file. Listing 1 shows you how to capture it.

Make sure the connection was successful and then, using a basic readable loop, pull the data over the network connection and write it to a file. While this process is interesting, it provides limited opportunity for getting the feeds for public calendars. In order to achieve more interesting results, such as letting users add events to their calendar or request a private feed, you'll need to fix it so they can log into their Google Calendar account.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap