Submit data to a Google Spreadsheet?

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

Submit data to a Google Spreadsheet?

Post by acidjazz » Mon Feb 16, 2009 4:44 am

Hi. I am new to databases and RunRev. Does does anyone know what happened to the following link. It is referenced in the tutorial on how to POST data using post (fill out a web form). But, I get an error message when I try to navigate to it:

http://www.runrev.com/workshops/sampleform.html

More to the point: I want to submit data to a Google Spreadsheet that I created, but from a RunRev application. I only have two fields (Name and Age),

Here is the link for the Spreadsheet:
http://spreadsheets.google.com/ccc?key= ... KdFvUgTEEA

Here is the link for a Google Form I created, that submits the data. I'd like to simply emulate what this form does, but in a RunRev application:
http://spreadsheets.google.com/viewform ... Z1RFRUE6MA..

I "viewed source" for the Google Form webpage, but I can't even tell exactly what google is calling the variables that represent name and age in the spreadsheet. Clearly, I am no expert! Interestingly, I did use the following command to try and submit just garbage to see what would happen and it actually creates a new line in the spreadsheet every time I run the script, so I feel like I'm halfway there!

put URLEncode("junk") into name
post name to URL "http://spreadsheets.google.com/formResp ... Z1RFRUE6MA.."


Thanks,
Mark

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Mon Feb 16, 2009 10:36 am

The field names that are being submitted are "entry.0.single" for the Name and "entry.1.single" for the Age.
If you make the data that's being posted look like: "entry.0.single=SparkOut&entry.1.single=154" for example (I'm not really that old) does that work?
You might find it easier to construct the data to post by using the libUrlFormData function, where you put the name/value pairs into the function and it works out the parameter string to post for you:

Code: Select all

local tFieldName1, tFieldName2, tFieldValue1, tFieldValue2, tDataToPost
put "entry.0.single" into tFieldName1
put "entry.1.single" into tFieldName2
put "SparkOut" into tFieldValue1
put 271 into tFieldValue2
put libUrlFormData (tFieldName1, tFieldValue1, tFieldName2, tFieldValue2) into tDataToPost
post tDataToPost to URL ("http://spreadsheets.google.com/formResponse?formkey=cDhvLXAxMkI3NnBtdktkRnZVZ1RFRUE6MA..")
I'm not sure if there are any other jiggery-poker headers that you will need to check for Google to accept, but how do you get on with this? (I posted a couple of lines, so you may see some entries for SparkOut in your sheet.)

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

Post by acidjazz » Mon Feb 16, 2009 5:34 pm

Thanks very much. I'll give it a try. By the way, what is the rationale for the convention of placing a lower case "t" before the variable names? I see this a lot in RunRev scripts.

Mark

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

Post by acidjazz » Mon Feb 16, 2009 5:43 pm

IT WORKED!
Thank you so much.

- Mark

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Tue Feb 17, 2009 12:04 am

acidjazz wrote:Thanks very much. I'll give it a try. By the way, what is the rationale for the convention of placing a lower case "t" before the variable names? I see this a lot in RunRev scripts.

Mark
Glad it worked.
The "t" is (often) short for "the" (as in "theData" or "theChunk") and serves as an indicator that it's a variable name, as opposed to a keyword, or function or parameter, etc. More specifically, and perhaps importantly, the "t" is often interpreted as "temporary" - ie a local variable, which has a value only within the local script in which it is referenced. "s" is often used as a prefix for "script local" (or sometimes "static") variables, which are referenced by several handlers in the same script. "g" is often used as a prefix for "global" variables, which retain their values between scripts.
There will always be some variation of coding styles (I use "c" prefix for custom properties, rather than "u" [user] for instance) but it's a handy idea to adopt a convention that people in the community will find familiar. (Different environments may well have different conventions. I personally can't help myself but use tArrStuff rather than tStuffA, but nobody is likely to be upset with me - I hope. When I code in VBS/VBA I generally declare variables with names according to type as well, eg intNumber, intValue, strName, strAddress.) In the end, anything that helps make your code clearer both to yourself and others who may be debugging/reusing etc will be of benefit.
Richard Gaskin gives some more depth on the subject here http://www.fourthworld.com/embassy/arti ... style.html

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

Post by acidjazz » Tue Feb 17, 2009 6:11 pm

This helps too. Thanks again.

jrioux
Posts: 50
Joined: Fri May 04, 2007 4:02 pm

Re: Submit data to a Google Spreadsheet?

Post by jrioux » Wed Dec 16, 2009 1:24 pm

I am also very new to databases... though not to Revolution. Should the above code snippet be adequate to POSTing data to a Google spreadsheet, or is there something crucial I'm missing (what about access? does the POST have to be submitted along with a userName and password? or does one do that earlier through another function?) My sole aim is to have copies of my application be able to write simple user data to a common (Google) file, which I can then check at my leisure. (Even a "highest score" routine would work for me.) Any suggestions?

Post Reply