Skip to content

Instantly share code, notes, and snippets.

@GieziJo
Last active May 5, 2021 08:57
Show Gist options
  • Save GieziJo/2173ebbc6dab31a6b7bc9987045c678f to your computer and use it in GitHub Desktop.
Save GieziJo/2173ebbc6dab31a6b7bc9987045c678f to your computer and use it in GitHub Desktop.
Download google docs sheet as string using unity editor coroutines and networking
using System.Collections;
using Unity.EditorCoroutines.Editor;
using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;
public static class ImportGoogleSheet
{
const string SHEET_ID = "";
const string SHEET_NAME = "";
const string owner = "";
[MenuItem("Utility/Download Sheet")]
public static void LoadSheet() => EditorCoroutineUtility.StartCoroutine(Method(), owner);
static IEnumerator Method()
{
UnityWebRequest request = UnityWebRequest.Get("https://docs.google.com/spreadsheets/d/" + SHEET_ID +
"/gviz/tq?tqx=out:csv&sheet=" + SHEET_NAME);
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError)
Debug.Log(request.error);
else
Debug.Log(request.downloadHandler.text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment