Beispiel #1
0
    public IEnumerator getFromAPI(GameObject g_obj)
    {
        //var render = GameObject.Find ("apiTest").GetComponent<TextMesh> ();
        var render   = g_obj.GetComponent <TextMesh>();
        var debugObj = GameObject.FindWithTag("DebugText");

        debugObj.GetComponent <TextMesh>().text = render.text;

        yield return(CredentialManager.getCredentials());

        string tok = CredentialManager.token;

        string url = "https://api.athenahealth.com/preview1/195900/patients/30621";


        Dictionary <string, string> content = new Dictionary <string, string> ();

        content.Add(CredentialManager.clientID, CredentialManager.secret);

        UnityWebRequest www = UnityWebRequest.Get(url);

        www.SetRequestHeader("Authorization", "Bearer " + tok);
        yield return(www.Send());

        if (www.responseCode == 200)
        {
            print("WWW Ok!: " + www.downloadHandler.text);
            String resultContent = www.downloadHandler.text;
            resultContent = resultContent.Substring(1, resultContent.Length - 2);
            PatientInfo json = JsonUtility.FromJson <PatientInfo>(resultContent);
            render.text = json.ToString();

            //render.text = "No crash?";
        }
        else
        {
            print("WWW Error: " + www.responseCode);
            print(www.downloadHandler.text);
            render.text = www.downloadHandler.text;
            //render.text = "ok something broke";
        }
    }