Reading Google Sheets with Unity
Help!
First of all: I am a complete beginner. And what do I do? I am trying to make a program for my sister so she could use it in her classroom
It's a simple program for students to make orders/see orders/see stock etc.
Came quite far, but I've been stuck for over a week now trying to figure out how to read data from Google Sheets.
What I am trying to do: Google Sheets has a column 'ID' which gets a random ID-number when I click send in Unity.
It works, but I want to display that number as soon as they hit Send.
I figured out how to SEND information to Google Sheets, but I am pulling my hair out trying to READ the information in the sheets.
Here's the code (which I'm certain isn't pretty):
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class SendToGoogle : MonoBehaviour
{
public GameObject naamVerkoper;
public GameObject naamKlant;
public GameObject adresKlant;
public GameObject woonplaatsKlant;
public GameObject productKeuze;
public GameObject aantalProduct;
public GameObject prijsProduct;
public GameObject datum;
public GameObject totaalPrijs;
public GameObject postcodeKlant;
public GameObject bestelnummer;
public Text bestelnummerTekst;
private string naamVerkoperS;
private string naamKlantS;
private string adresKlantS;
private string woonplaatsKlantS;
private string productKeuzeS;
private string aantalProductS;
private string prijsProductS;
private string datumS;
private string totaalPrijsS;
private string postcodeKlantS;
private string bestelnummerUitGoogle;
public GameObject button1;
public GameObject button2;
public InputField mainInputField;
EventSystem system;
[SerializeField]
private string BASE_URL = "https://docs.google.com/forms/d/e/1FAIpQLSfcO_SocAuZsrAGgi_nIj4451MmN5Q5sL7mpat2WKOaPdOYcw/formResponse";
private object prettyPrint;
void Start()
{
mainInputField.ActivateInputField();
system = EventSystem.current;
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
Selectable next = system.currentSelectedGameObject.GetComponent<Selectable>().FindSelectableOnDown();
if (next != null)
{
InputField inputfield = next.GetComponent<InputField>();
if (inputfield != null)
inputfield.OnPointerClick(new PointerEventData(system));
system.SetSelectedGameObject(next.gameObject, new BaseEventData(system));
}
}
}
IEnumerator Post(string naamVerkoper, string naamKlant, string adresKlant, string woonplaatsKlant, string productKeuze, string aantalProduct, string prijsProduct, string datum, string totaalPrijs, string postcodeKlant)
{
WWWForm form = new WWWForm();
form.AddField("entry.499561005", naamVerkoper);
form.AddField("entry.1868025165", naamKlant);
form.AddField("entry.1552584854", adresKlant);
form.AddField("entry.1829297357", woonplaatsKlant);
form.AddField("entry.1690053122", productKeuze);
form.AddField("entry.759770034", aantalProduct);
form.AddField("entry.693687310", prijsProduct);
form.AddField("entry.2056630187", datum);
form.AddField("entry.106947741", totaalPrijs);
form.AddField("entry.1985875803", postcodeKlant);
byte[] rawData = form.data;
WWW www = new WWW(BASE_URL, rawData);
yield return www;
}
public void Send()
{
naamVerkoperS = naamVerkoper.GetComponent<InputField>().text;
naamKlantS = naamKlant.GetComponent<InputField>().text;
productKeuzeS = productKeuze.GetComponent<InputField>().text;
adresKlantS = adresKlant.GetComponent<InputField>().text;
woonplaatsKlantS = woonplaatsKlant.GetComponent<InputField>().text;
aantalProductS = aantalProduct.GetComponent<InputField>().text;
prijsProductS = prijsProduct.GetComponent<InputField>().text;
datumS = datum.GetComponent<InputField>().text;
totaalPrijsS = totaalPrijs.GetComponent<InputField>().text;
postcodeKlantS = postcodeKlant.GetComponent<InputField>().text;
StartCoroutine(Post(naamVerkoperS, naamKlantS, adresKlantS, woonplaatsKlantS, productKeuzeS, aantalProductS, prijsProductS, datumS, totaalPrijsS, postcodeKlantS));
}
public void enableButton()
{
bool buttonclicked = true;
if (buttonclicked)
{
button1.SetActive(true);
button2.SetActive(false);
bestelnummer.SetActive(true);
bestelnummerTekst.text = "Bestelnummer: " + bestelnummerUitGoogle;
}
else
{
button1.SetActive(false);
button2.SetActive(true);
bestelnummer.SetActive(false);
}
}
}
And the thing waaaay down at the bottom 'bestelnummerUitGoogle' (yes, I'm Dutch) should be the number generated in Google Sheets so it can be displayed in unity (which now only says Bestelnummer:)
Is it clear what the question is? I hope so...
(After that I need to search the database for a specific ID, but first I want this solved)