Its been 3 days since I am struggling to get LED on off via Web app Example work through API. It appeared to me that Access token is no more valid which is shown in Build. I created more tokens also.
I also tried generating new tokens and using them all. None worked. Now I have deleted the redundant ones. And still only Spark Dev Works on my Mac to write the cloud functions. Nothing else does. If I enter CURL from command prompt or from Web Page, I get error 403.
Currently there are 3 tokens issues to me. And none of them is working, I need guidance how to encode them or access through my web app and command line.
# You type in your terminal
curl https://api.spark.io/v1/devices \
-d access_token=xxxxxxxxxxxxxx
# Response status is 200 OK, which means
# the Core says, "Yes ma'am!"
I am sorry in advance for posting noob level questions. Thanks for prompt response here. Dear @kennethlimcp I am still getting same error. Actually I am trying to run the jQuery AJAX with Device ID and Access Token stored in HTML file. It appears that:
But when I press the key on my web app it returns this error in console:
{
"error": "Permission Denied",
"info": "I didn't recognize that core name or ID, try opening https://api.spark.io/v1/devices?access_token=08dxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx5b "
}
Here is HTML code:
var accessToken = "08dxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx5b";
var deviceID = "53ff6cXxXxXxXxXxXxXxXxXx5"
var url = "https://api.spark.io/v1/devices/" + deviceID + "/led";
function switchOn()
{
$.post(url, {params: "on", access_token: accessToken });
}
function switchOff()
{
$.post(url, {params: "off", access_token: accessToken });
}
<body>
On/Off Control</h1>
input type="button" onClick="switchOn()" value="ON"/>
input type="button" onClick="switchOff()" value="OFF"/>
The error message is saying it doesn’t recognize your Core ID, whereas the accesstoken appears to be correct.
In your API browser response, the CoreID ends on a 7 and in your web app on a 5. I don’t know if your using different cores, but that might be a cause of problems. Try issuing the browser API command, and then copy&paste the CoreID it gives you into your webapp.
Thanks @Moors7 for your kind help. I think the solution was in manually typing the Spark Core ID in HTML file. It just got working. Matter resolved. Thank you Spark Community.