问题
How can I add value on the other section on Google forms in unity3d?
I can only add values on section 1. I am having trouble on adding values on other sections.
here is the code
public GameObject username;
public GameObject email;
public GameObject phone;
public GameObject phone2;
private string Name;
private string Email;
private string Phone;
private string Phone2;
[SerializeField]
private string BASE_URL = "https://docs.google.com/forms/d/e/1FAIpQLSc8rwjEYJ0akVuuRo0GULsoyhvBxgLwuvv6oDtWiJgJZjyiMw/formResponse";
IEnumerator Post(string name, string email, string phone, string phone2) {
WWWForm form = new WWWForm();
form.AddField("entry.1417744726", name);
form.AddField("entry.881581736", email);
form.AddField("entry.977000887", phone);
form.AddField("entry.1897661126", phone2);
byte[] rawData = form.data;
WWW www = new WWW(BASE_URL, rawData);
yield return www;
}
public void Send() {
Name = username.GetComponent<InputField>().text;
Email = email.GetComponent<InputField>().text;
Phone = phone.GetComponent<InputField>().text;
Phone2 = phone2.GetComponent<InputField>().text;
StartCoroutine(Post(Name, Email, Phone, Phone2));
}
回答1:
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.
In terms of the section issue your facing, in the google apps script javascript thats not too much an issue, as the sections are just used to visually break the front end up and they don't affect the data. However they are represented as an "item" in the backend, so when you are copying the answers from the JSON payload to the form responses be mindful which index your sections are so you can skip them and not accidentally loss data.
来源:https://stackoverflow.com/questions/57767790/how-to-add-value-on-another-section-in-google-form-in-unity3d