Any Parse.com Experts?

I’m really struggling to add an object to a class I’ve created via the Parse.com Database. My code is as follows:

[lua]

local data = {
                [“ID”] = “1”, 
                [“Day_Pollen”] = “0”,
                [“Total_Pollen”] = “0”,
                [“Garden_Value”] = “0”
            }
       
            local postData = json.encode(data)
            print("postData: "…postData)
       
            local headers = {}
            headers[“X-Parse-Application-Id”] = “xxxxxxxxxxxxxxxxxxxxx”
            headers[“X-Parse-REST-API-Key”] = “xxxxxxxxxxxxxxxxxxxxx”
            headers[“Content-Type”] = “application/json”
       
            local params = {}
            params.header = headers
            params.body = postData
       
            network.request( “https://api.parse.com/1/classes/Gardens”,“POST”,foo, params)

[/lua]

However I’m getting the following table back in my listener function:

{“error”:“unauthorized”}

Spent all day looking at Parse.com Q&A, StackOverflow - but no joy so far, so hoping somebody might be able to assist.

Many thanks…

OK this is really stupid (or it could possibly be me :slight_smile: )

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?!?

OK this is really stupid (or it could possibly be me :slight_smile: )

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?!?

I’m also having a problem with Parse.

I’m also getting: an unauthorized error.

My code is:

local inspect = require("inspect") local parse = require( "mod\_parse" ) APPID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' RESTAPIKEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' parse:init( { appId = APPID, apiKey = RESTAPIKEY } ) parse.showStatus = true local function getit()     print ("getObject")     local function gotObject(event)         print ("gotObject")         if event.error then             print (inspect(event))         else             local text = event.response.Text             print ("Text='"..text.."'")         end     end      parse:getObject( 'Coffee', 'J9xXWVURgM', gotObject  ) end timer.performWithDelay( 1000, function() getit(); end )

(xxxx… replaces my AppId and RestApiKey)

When I run it I get:

Copyright © 2009-2013  C o r o n a   L a b s   I n c .

    Version: 3.0.0

    Build: 2013.2100

getObject

Success!

Success!

gotObject

{

  error = “unauthorized”,

  name = “parseRequest”,

  requestId = <userdata 1>,

  requestType = “ERROR”

}

Any ideas why my request is not working?

Suhada

I’ve asked develephant at www.develephant.net as he’s probably best placed to answer my query.

Thanks

Suhada

I’m also having a problem with Parse.

I’m also getting: an unauthorized error.

My code is:

local inspect = require("inspect") local parse = require( "mod\_parse" ) APPID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' RESTAPIKEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' parse:init( { appId = APPID, apiKey = RESTAPIKEY } ) parse.showStatus = true local function getit() &nbsp; &nbsp; print ("getObject") &nbsp; &nbsp; local function gotObject(event) &nbsp; &nbsp; &nbsp; &nbsp; print ("gotObject") &nbsp; &nbsp; &nbsp; &nbsp; if event.error then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print (inspect(event)) &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local text = event.response.Text &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print ("Text='"..text.."'") &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; parse:getObject( 'Coffee', 'J9xXWVURgM', gotObject &nbsp;) end timer.performWithDelay( 1000, function() getit(); end )

(xxxx… replaces my AppId and RestApiKey)

When I run it I get:

Copyright © 2009-2013  C o r o n a   L a b s   I n c .

    Version: 3.0.0

    Build: 2013.2100

getObject

Success!

Success!

gotObject

{

  error = “unauthorized”,

  name = “parseRequest”,

  requestId = <userdata 1>,

  requestType = “ERROR”

}

Any ideas why my request is not working?

Suhada

I’ve asked develephant at www.develephant.net as he’s probably best placed to answer my query.

Thanks

Suhada