1

Is it still possible to programmatically send "responces" to Google Forms. Preferably without users logging in. I think they changed the protocol.

In a unity application, I need to setup a survey, and the obvious choice was google forms, since a friend of mine did in the past. However, after implementing some test code from a tutorial, I can't get responses through and not receiving any data despite following a tutorial. Instead it complains about 401 unauthorized error. Heres some code :

private string target_url = 
    "https://docs.google.com/forms/myForm/formResponse";

private IEnumerator RoutineSendActual()
{
    WWWForm form = new WWWForm();
    form.AddField( "entry.689820410", "code test" );

    var www = new WWW( target_url, form.data );
    Debug.Log( www.url );

    yield return www;

    Debug.Log( "sent " + www.error + " " + www.isDone + " " + www.responseHeaders);

    foreach ( var responseKey in www.responseHeaders.Keys )
    {
        Debug.Log( responseKey + "|" + www.responseHeaders[responseKey] );
    }

    Debug.Log( www.text );

    yield break;
}

Instead www.error is giving me 401 unauthorized error. I've followed the following tutorial https://www.youtube.com/watch?v=z9b5aRfrz7M and the following questions has it working How to add value on another section in google form in Unity3d

but for me, I get 401 unauthorized. I even made sure the Forms and spreadsheet where made public and editable to everyone (which i'm worried about because could hack the data).

Also, should I instead be looking into Google Apps Script to act as an intermediary between unity web request and the actual form.

  • You probably still need to authenticate as a google account. Have a look at [UnityWebRequest Embedding User + Password data for HTTP Basic Authentication not working on Android](https://stackoverflow.com/a/39489237/7111561). I would anyway suggest to rather use [`UnityWebRequest.Post`](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Post.html) instead of the **obsolete** [`WWW`](https://docs.unity3d.com/ScriptReference/WWW.html) – derHugo Sep 04 '19 at 08:55
  • At some point in the discussion around the tutorial, it was mentioned that for this purpose unity web request wouldn't work and instead WWW was used because of how it formatted the request I guess. – CodeSloth42 Sep 04 '19 at 22:55
  • @derHugo Also, I'm pretty sure that Question you linked is for a different service. – CodeSloth42 Sep 04 '19 at 23:07
  • Just implemented the unity web request post to test. still the same problem. – CodeSloth42 Sep 04 '19 at 23:22
  • this person https://stackoverflow.com/questions/57767790/how-to-add-value-on-another-section-in-google-form-in-unity3d has got it working, their question is about something different, but they got the initial post working. However I don't have enough reputation atm to comment to ask them about. – CodeSloth42 Sep 04 '19 at 23:30
  • The service doesn't matter .. I just said maybe you have to pass in the `Authentication` header .. `UnityWebRequest` is simply the new standard and `WWW` going to be deprecated in the future so sooner or later you will have to switch anyway ;) – derHugo Sep 05 '19 at 06:40

2 Answers2

0

{ Note: I'm copying this from another question I answered, but I considered it an answer to my own question }

Unfortunately, it seems that this method of posting info to google forms is unreliable, as it's not well documented at all progress here is from looking at the html page code. I've followed the same tutorial and also having trouble.

But fortunately, I've found a better solution that gives you better control and access to google forms.

https://developers.google.com/apps-script/

https://developers.google.com/apps-script/reference/forms/

Instead of guessing the post API, using Google Apps Script, you can setup and deploy a web app from googles own servers in javascript, and interface with forms directly. From there you just have to design JSON payload. I got it working already using Postman to simulate the web request that will be sent from unity.

  • Please don't copy from other answers .. even less if not at least linking to it. Rather upvote the other answer and leave a comment on the question .. and probably it will then be closed as duplicate anyway – derHugo Sep 05 '19 at 06:41
0

Check that the Google Form has public permissions. Maybe you have set them to a single user or to a single organization.

Misael L.
  • 261
  • 1
  • 3
  • 4