Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple API Caller example in Unity JS
#pragma strict
import SimpleJSON;
function Start () {
}
function Update () {
}
function GetUser() {
var url = "https://api-jp.kii.com/api/apps/e2073bca/users/7b3f20b00022-a998-5e11-719d-0dd420df";
var form = new WWWForm();
var headers = form.headers;
var authToken = "put users token here.";
headers["Authorization"] = "Bearer " + authToken;
headers["X-Kii-Appid"] = "e2073bca";
headers["X-Kii-Appkey"] = "dc96b9a23cfe23ae1c68c87ebb067e2a";
var www:WWW = new WWW(url, null, headers);
yield www;
Debug.Log(www.text);
Debug.Log(www.isDone);
Debug.Log(www.error);
var data = JSON.Parse(www.text);
Debug.Log(data["_emailAddressPending"]);
Debug.Log(data["emailAddress"]);
}
function OnGUI() {
if(GUI.Button(Rect(20,20,100,50),"Button")) {
GetUser();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment