RSS

Using Google Docs As A WebService

22 Jun

I picked up this little gem of a trick from Herman Lintvelt’s (@hermanlintvelt) Domain Specific Language (DSL) talk, at AppsWorld Africa at the beginning of the month, where he walked through the processes of creating a DSL for a SASSI Pocket Guide app for Android and iOS.  His example used a Google Spreadsheet to maintains the status of indigenous to South Africa, and  using the ‘Publish as a web page”feature, he demonstrated how the Spreadsheet RSS export be used as a webservice…niffty, huh!

In this post, I’ll demonstrate how to do it using PhoneGap and XUI.

Firstly we’ll create some data in a Google Doc Spreadsheet, then “Publish as a web page” in ATOM format:

A good option to set is “Automatically republish when changes are done”.


Great! Now we’ve got data we can use in our mobile app. Next, we’ll need to add some Javascript to our PhoneGap app to request our webservice data using XUI.

The Javascript code for XUI (using XHR) looks something like this:

What the function does is make a XUI XHR request to the Spreadsheets ATOM feed to read the data. It then iterates the each of the <entry> elements (each <entry> element represents a row in the Spreadsheet.

We then read each cell value (maintained in the <content> element) to build up the Header row and data row(s) and a HTML table which we then set as the document element with the id “ui_events”.

The Javascript method can be invoked by a timer or when a button is pressed.

Advertisements
 
15 Comments

Posted by on June 22, 2011 in Mobile

 

Tags: , ,

15 responses to “Using Google Docs As A WebService

  1. Bernhard

    June 23, 2011 at 10:42

    FYI: You blurred part of the URL in the docs screenshot, but not in the code (https://thepseudocoder.files.wordpress.com/2011/06/blog22june2011_4.jpg).

    Great post, thank you for sharing it. I’m itching to use this somewhere now. 🙂

     
    • mitchwongho

      June 23, 2011 at 11:50

      Thanks, Bernhard.

      Yeah. I noticed that just after I published the post. It’s not production code, so I can easily create new new feed.

      Let me know how it works our for you. Happy coding

       
  2. onursencer

    June 24, 2011 at 14:46

    thanks for the post, it would be perfect if we could also write data to the service 🙂

     
  3. Herman Lintvelt

    June 24, 2011 at 15:14

    Hi Mitch

    Thanks for the mention.

    I must just point out I learned this trick from Heiko Behrens and Peter Friese in a talk by Heiko. More here.

     
    • mitchwongho

      June 24, 2011 at 15:48

      Hi Herman,

      Thanks again for the great discussion at AppsWorld Africa. Also, thanks for passing on the credits for the trick 🙂

       
  4. Ron

    June 24, 2011 at 17:34

    Did Google change the Google Docs share functionality? Or, is it different for Google Apps users vs. regular users?

    I’m not getting the ATOM option as one of the choices, nor can I get an RSS export. Just the usual HTML, etc.

     
    • Ron

      June 24, 2011 at 17:38

      Never mind the question.

      I was able to confirm that the ATOM and RSS options only appear with regular Google accounts, not Google Apps user accounts (they run a different release version of the apps).

       
      • mitchwongho

        June 24, 2011 at 20:30

        Hi Ron,

        Thank you for visiting and your comments.

        I believe that Google Apps is meant to run within an organisation.

        Thanks for following up on this restriction

         
  5. Ron Manke

    June 24, 2011 at 21:33

    Actually Google Apps works outside of organizations as well. It’s possible to export spreadsheets into a live view HTML or a variety of other formats.

    They tend to lag behind on new features, because the Google team has a different release schedule for Apps customers (probably because they have to review functionality for security, etc.)

    Thanks for the useful article!

     
  6. Rohit

    January 2, 2013 at 07:18

    Hi mitchwongho,
    I just want to ask that is there any way to avoid google login so i can authenticate a person programmatically….!

     
    • mitchwongho

      January 2, 2013 at 08:54

      Hi,I believe you only need to make the document ‘Public’ in the Share options

       
      • Rohit

        January 3, 2013 at 08:10

        plz rply fast

         
      • Rohit

        January 4, 2013 at 05:36

        Hello mitchwongho,
        I am having private docs in my google drive.i have set the scope and role for those docs. if any user want to view those document they have to enter the id and password. is there any way we can pass id and password programmatically so there is no need for the user to enter his id and password.plz rply.

         
  7. Rohit

    January 2, 2013 at 12:45

    Thnx for rply mitchwongho……
    I dont want to make it public.i want the docs to remain private but i want those user who are authorized to view those document can view the document without logging through their google account.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: