Access token problem

How to check output on cloud? I am doing led blinking on web experiment it is giving me that access token not found but i have added right access token.what should i do?

To execute a function from a change in state of the radio buttons? Check out the jquery in this checkbox example:

function handleCheckBox(checkBox)
{
  var newValue = checkBox.checked == true ? 1 : 0;
  var requestURL = "https://api.spark.io/v1/devices/" + deviceID + "/" + deviceFunction + "/";
	$.post(requestURL, {
		params: newValue,
		access_token: accessToken
	});
}

if you want to verify that it happened, you can use AJAX/jquery to update the status of the buttons:


$.ajaxSetup({
    timeout: 5 * 1000
});

window.onload = function() {
    getParticleData();
}

var refreshAjax = function() {
    getParticleData();

var timer = window.setInterval(refreshAjax, 10000);
}

and the actual function:

function getParticleData()
{
	var myURL = "https://api.spark.io/v1/devices/" + deviceID + "/" + deviceVariable + "/?access_token=" + accessToken;
	$.getJSON(myURL, function(data) {
	var state = parseInt(data.result);
	console.log("device state =" + state);
	document.getElementById("myCheckBox").checked = ((state == 1)? true : false);
	});
}

try adding:

console.log(data);

(in the above example) to see the actual JSON returned from your device.

3 Likes

Do i need to change in my code or what shall i do? i am still not understanding.Can you tell me step wise so i can follow easily. what is particle,function?how to registered that?

Give this tutorial a try: Tutorial: Spark Variable and Function on One Web Page

2 Likes