问题
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).
回答1:
You have a handler setPostHeaders
, which suggests that you need to use the POST instead of the GET method. If that's true, you need to change part of your script.
put urlEncode ( JSON_stringified ( tLoginA ) ) into tLogin
post tLogin to url "https://api.parse.com/1/login"
put the result into rslt // check for errors if not empty
put the urlResponse into myResponse // empty if error occurred
Provided that the parse.com part of your script is correct, this should work.
回答2:
According to the docs: "send a GET request to the /1/login endpoint with username and password as URL-encoded parameters"
Try the following;
put "username=" & urlEncode("YourUser") & "&password=" & urlEncode("YourPass") into tLogin
get url ( "https://api.parse.com/1/login?" & tLogin )
来源:https://stackoverflow.com/questions/25217150/200-error-missing-username-when-logging-in-using-parse-and-livecode