I am trying to login to Parse through LiveCode but keep getting this error:
{"code":200,"error":"missing username"}
I have been able to create users, even validate user's email (through the REST API in Parse) but when I try to login I keep getting an error. I think there is something wrong with my JSON formatting or the GET call but I can't figure it out.
command mainLogin
local tLoginA, tLoginJson, tReturn, tLogin
setHeaders
put fld "username" into tLoginA [ "username" ]
put the cPassword of fld "password" into tLoginA [ "password" ]
put urlEncode ( JSON_stringified ( tLoginA ) ) into tLogin
put urldecode ( tLogin ) --testing
get url ( "https://api.parse.com/1/login?" & tLogin )
put it --testing
put JSON_parsed ( it ) into tReturn
if ( tReturn [ "error" ] <> empty ) then
answer "Please try again: " & tReturn [ "error" ]
end if
if ( tReturn [ "sessionToken" ] is NOT empty ) then
//user logged in successfully
put tReturn [ "sessionToken" ] into sSessionToken
put tReturn [ "objectid" ] into sObjecteID
answer "Welcome " && tLoginA [ "username" ]
mainClearFields
end if
end mainLogin
The functions JSON_parsed()
and JSON_stringified()
are from a JSON library by Andreas Rozek.
Update
I pulled this from the Parse.com REST API documentation on logging in:
After you allow users to sign up, you need to let them log in to their account with a username and password in the future. To do this, send a GET request to the /1/login endpoint with username and password as URL-encoded parameters...
I get that conceptually but I can't get it to work.
Thanks Mark for your comment. I see that I was using the Post header handler which has the Content-Type: application/json
added but that doesn't change much. According to the Parse.com docs the GET verb is the proper one (I changed the code to show the new header handler).