OK this is really stupid (or it could possibly be me
)
Can anybody explain why Button3 always works fine (get a response back from Parse and an object is entered into the class), and yet Button4 which by all intent and purposes is exactly the same fails with an authentication error?!?
[lua]
elseif event.target.id == “button_3” then
local function registerNewUser(event)
print(“registerNewUser”)
if event.phase == “ended” then
local response = event.response
print(response)
local t = json.decode(response)
if t.error ~= nil then
title = “Oops!”
msg = t.error
else
title = “Success!”
msg = “You’re now a registered user of the Dessert-O-Meter!”
end
local alert = native.showAlert( title, msg, {“OK”}, onComplete )
end
end
local headerData = json.encode(headers)
print("headerData: "…headerData)
local commands_json = {
[“ids”] = 1, --t.objectId,
[“Day_Pollen”] = 0,
[“Total_Pollen”] = 0,
[“Garden_Value”] = 0
}
local postData = json.encode(commands_json)
print("postData: "…postData)
local params = {}
params.headers = headers
params.body = postData
network.request( “https://api.parse.com/1/classes/Garden”,“POST”,registerNewUser,params)
print( “You pressed and released button3!” )
elseif event.target.id == “button_4” then
local function foo(event)
print(“foo”)
if event.phase == “ended” then
local response = event.response
print(response)
local t = json.decode(response)
if t.error ~= nil then
title = “Oops!”
msg = t.error
else
title = “Success!”
msg = “You’re now a registered user of the Dessert-O-Meter!”
end
local alert = native.showAlert( title, msg, {“OK”}, onComplete )
end
end
local headerData = json.encode(headers)
print("headerData: "…headerData)
local data = {
[“ID”] = 1,
[“Day_Pollen”] = 0,
[“Total_Pollen”] = 0,
[“Garden_Value”] = 0
}
local postData = json.encode(data)
print("postData: "…postData)
local params = {}
params.header = headers
params.body = postData
network.request( “https://api.parse.com/1/classes/Garden”,“POST”,foo,params)
print( “You pressed and released button4!” )
[/lua]
P.S I’m encoding the header table just to make sure everything is correct - and it does seem to be exactly the same for both calls. The table headers is set with the relevant data at the top of the file, it’s the same data for Button3 and Button4?!?