Google Forms New Format

Getting into LiveCode for iOS? Ask your questions here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
teacherguy
Posts: 348
Joined: Thu Dec 08, 2011 2:43 am

Google Forms New Format

Post by teacherguy » Sun Feb 02, 2014 4:23 am

Thanks to several people here I have been able to record student scores via google forms (post myData to url....). However, soon Google is migrating all forms/spreadsheets to a new format (see: https://support.google.com/drive/answer ... grate&rd=1), and I have not had success in getting form data to post into these new spreadsheets. I am really hoping they are not closing the door on the ability to post data.

The old url (prior to the key) for forms looks like so:

https://spreadsheets.google.com/formResponse?formkey=

But the new ones are very different:

https://docs.google.com/forms/d/

Has anyone had success with this?

teacherguy
Posts: 348
Joined: Thu Dec 08, 2011 2:43 am

Re: Google Forms New Format

Post by teacherguy » Tue Sep 23, 2014 2:21 am

Just bringing this thread back to the top. Google has indeed deprecated the old format. I'd be grateful if anyone has figured out a way to submit data into google spreadsheets with the forms' new key format.

teacherguy
Posts: 348
Joined: Thu Dec 08, 2011 2:43 am

Re: Google Forms New Format

Post by teacherguy » Tue Sep 23, 2014 5:14 pm

Update:

Looks like google no longer allows form data to be sent in one long url. If anyone knows how to create "post" data I would appreciate any insight. Here is what I found:


"Please excuse any part of this explanation that might come off as too simple. Wanted to point out a couple things in case you weren't aware.
When you build a URL with query variables that looks like this example.com?key=value&otherkey=othervalue you are using what web developers refer to as GET syntax. It is generally believed to be insecure (as the entire URL, and thus all the data you sent, shows up in the server logs and is easy to intercept).

Because of this, Google has shifted to a method that is more frequently used known as POST. When you use GET on a web form (like the old Google form) it creates a URL with all the keys and values and then hits that URL and a script file decodes it right from the URL.

When you do the same with a POST form, the URL in the "action" attribute of the form tag is called as-is and the data is POSTED to the server behind the scenes.

Here's a copy of my form for your reference. I've omitted all of the Javascript submission stuff, as the part of the form you're most interested in doesn't use it."
And here is an example of the POST format, but I don't know if I can replicate this with LiveCode?

Code: Select all

<form action="https://docs.google.com/forms/d/16TltcvKi2nph-wora13uedVGJ5k6rr4MwTeLh1lfmkc/formResponse" method="POST" id="ss-form">

<h1>Inventory Tagging
<br>San Diego</h1>
<p>
<label class="ss-q-title" for="entry_1">Site Number</label>
<input type="text" name="entry.1" value="" class="ss-q-short" id="entry_1" maxlength="9">
</p>
<p>
<label class="ss-q-title" for="entry_2">Bin</label>
<input type="text" name="entry.2" value="" class="ss-q-short" id="entry_2" maxlength="6">
</p>
<p id="message">Updated</p>
<p>
<input type="submit" name="submit" value="Submit" id="submit">
</p>

</form>
The actual data I need to post is:

StudentName
StudentInstrument
StudentMinutes (how long they played the game)
StudentLevel
StudentScore
StudentPercentage
tCourse
tTeacher

Thank you for any help.

teacherguy
Posts: 348
Joined: Thu Dec 08, 2011 2:43 am

Re: Google Forms New Format

Post by teacherguy » Tue Sep 23, 2014 11:40 pm

Made some progress. I used "get" to retrieve the data from my google form and found that they have changed the way they refer to each entry. Formerly you would set up the post like so:

Code: Select all

  put "entry.0.single" into tFieldName1
      put "entry.1.single" into tFieldName2
      put "entry.2.single" into tFieldName3
      put "entry.3.single" into tFieldName4
And now it's like:

Code: Select all

  put "entry.1000000=" into tFieldName1
   put "entry.1000001=" into tFieldName2
   put "entry.1000002=" into tFieldName3
   put "entry.1000003=" into tFieldName4
Then you assign your values, such as:

Code: Select all

 put studentName into tFieldValue1
put "&" after tFieldValue1
You need the ampersand so the values will all be strung together for the post.

Once you've done that you can build the post:

Code: Select all

 put tFieldName1&tFieldValue1&tFieldName2&tFieldValue2&tFieldName3&tFieldValue3&tFieldName4&tFieldValue4 into myList
To set up the post, this is the new format:

Code: Select all

put  "https://docs.google.com/forms/d/YOURGOOGLEKEYHERE/formResponse" into tformKey
And then finally

Code: Select all

post myList to URL tformKey

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

Re: Google Forms New Format

Post by acidjazz » Sat May 16, 2015 5:41 am

This reply is a bit late, but would you be willing to share example code of using the GET command to retrieve data from Google Sheets? I used your code to save data, and it works like a charm, but can't quite figure out how to read from the spreadsheet.

Thanks,
Mark

teacherguy
Posts: 348
Joined: Thu Dec 08, 2011 2:43 am

Re: Google Forms New Format

Post by teacherguy » Sat Jun 06, 2015 11:46 am

Hi Mark, I'm really sorry for only seeing this now. Here is how I pull the info from a google spreadsheet. Of course, the spreadsheet privacy must be set to "anyone with the link"

As you probably know, all google docs have an identifying "key" that can be found in the url. So:

Code: Select all

   put <yourKeyHere> into tPrefsKey
   put "https://spreadsheets.google.com/a/google.com/tq?tqx=out:json&tq=select%20A,B,C,D%20order%20by%20A%20desc&key=" into tFirstPart
   put tFirstPart&tPrefsKey into wholeURL
   libURLSetSSLVerification false
   get url wholeURL
   put it into preGArray
This will give you a json result that you can parse. I included the statements for sorting just so you could see what that looks like. The %20 are all in place of spaces.

See also: https://coderwall.com/p/pluhsg/google-s ... -filtering

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

Re: Google Forms New Format

Post by acidjazz » Thu Jun 25, 2015 2:23 am

And thanks for the response. It appears that we teachers don't check here often enough!
- Mark

simon.schvartzman
Posts: 183
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Google Forms New Format

Post by simon.schvartzman » Tue Jul 17, 2018 10:36 pm

Hi @teacherguy & @acidjazz, despite the fact that is an old post I decided to give it a try instead of starting a new one about the some subject.

I've followed the guidelines with no luck.

My "Post" code is:

Code: Select all

on mouseUp
   put "-----------------------" into myKey
   put "entry.Question1=" into tFieldName1
   put "Answer2" into tFieldValue1
   put "&" after tFieldValue1
   
   put tFieldName1&tFieldValue1 into myList
   put  "https://docs.google.com/forms/d/" into tformKey
   put myKey & "/formResponse" after tformKey
   answer tformKey
   post myList to URL tformKey
   answer the result
end mouseUp
and even though I get no error and a new entry is created in the spreadsheet it has no answer as can be seen on the picture below (I guess I'm doing something wrong with the fieldName):
ss.jpeg
On the other hand when I try to "Get" the contents of the spreadsheet with the following code

Code: Select all

on mouseUp
   put "--------------------------" into tPrefsKey
   put "https://spreadsheets.google.com/a/google.com/tq?tqx=out:json&tq=select%20A,B,C,D%20order%20by%20A%20desc&key=" into tFirstPart
   put tFirstPart&tPrefsKey into wholeURL
   libURLSetSSLVerification false
   get url wholeURL
   answer it
end mouseUp
I get the error in the attached picture.

Any hint or suggestion would be very much appreciated. What I'm trying to achieve is a very simple App that would log the mobile GPS location to the spreadsheet.

Many thanks!
Attachments
get.jpg
Simon

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

Re: Google Forms New Format

Post by acidjazz » Tue Jul 17, 2018 10:44 pm

It seems that Google changes how it works so often that it's almost not worth trying to keep up with it. I've almost completely abandoned LiveCode because the html5 functionality is just not where it needs to be (nor does it look like it ever will be), and have just had to teach myself javascript. Very frustrating, but not much we can do, I guess.

:( Mark

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6173
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Google Forms New Format

Post by FourthWorld » Tue Jul 17, 2018 11:39 pm

acidjazz wrote:
Tue Jul 17, 2018 10:44 pm
It seems that Google changes how it works so often that it's almost not worth trying to keep up with it. I've almost completely abandoned LiveCode...
I'm not clear: if the problem with LiveCode or with Google's API changes? Was your script working well before Google changed?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: Google Forms New Format

Post by acidjazz » Wed Jul 18, 2018 12:10 am

Richard,

To be fair, I haven't tried this script for years now, so I can't really speak to it directly. My comments were directed at a few different frustrations and I did it in an unclear fashion. Let me restate. I have abaondoned LiveCode mostly because I run experiments online, and the html version just doesn't do what I need, at least not without having to interject javascript a lot. So, I finally just bit the bullet and am doing everything via javascript. I love livecode, and if I were only using it in the lab (offline) I'd be happy.

As for the Google API, I also haven't tried it in a while, because I got frustrated with that too, because it's a pain. So, I use my own server, and write in HTML, javascript, and CSS and save simple textfiles. I just might not be smart enough to do more.

- Mark

simon.schvartzman
Posts: 183
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Google Forms New Format

Post by simon.schvartzman » Wed Jul 18, 2018 2:16 am

Just an update on my previous post.

I was able to get the Post to work properly, it was in fact a problem with the fieldName I was using. This is how I solved it:
1 - Open the Form source code
2 - Search for the text of question (Question1 in my case)
3 - Just after the second occurrence (see below) you can find name="entry.1775847828"
aria-label="Question1" aria-describedby="i.desc.170916459 i.err.170916459" name="entry.1775847828" value="" dir="auto" data-initial-dir=
4 - Use

Code: Select all

put "entry.1775847828=" into tFieldName1
5 - Bingo!!!

I still would like to have the GET part working...

Best
Simon

teacherguy
Posts: 348
Joined: Thu Dec 08, 2011 2:43 am

Re: Google Forms New Format

Post by teacherguy » Fri Sep 21, 2018 1:07 pm

Simon my apologies for not seeing this until now. Have you been able to use "GET" at this point? I am still able to use it and I can dig into my code and see what changes I had to make.

simon.schvartzman
Posts: 183
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Google Forms New Format

Post by simon.schvartzman » Fri Sep 21, 2018 10:50 pm

Hi @teacherguy, no worries I got it working...all good

thanks for getting back to me

Cheers
Simon

Post Reply

Return to “iOS Deployment”