So, I am trying to use the REST API to access my firebase database, but unitywebrequest is giving me some issues.
I have noticed that the code I have returns the html code of the page only for certain websites (I have tried it with www.google.com) but with other websites (like www.youtube.com or my firebase database website) it just returns a response code of 0 and an empty message.
Any idea on what could be causing this? I am a newbie when it comes to APIs and get/post requests.
My code:
public class DatabaseHandler : MonoBehaviour
{
string url = "https://locked-3426c.firebaseio.com/levels.json";
void Start()
{
StartCoroutine(GetLevelsCoroutine());
}
IEnumerator GetLevelsCoroutine()
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
DownloadHandlerBuffer dH = new DownloadHandlerBuffer();
www.SetRequestHeader("X-Firebase-Decoding", "1");
www.SetRequestHeader("Accept", "text/event-stream");
www.downloadHandler = dH;
yield return www.SendWebRequest();
Debug.Log(www.responseCode);
string result = www.downloadHandler.text;
Debug.Log(result);
}
}
}