200 error: missing username when logging in using Parse and LiveCode

跟風遠走 提交于 2019-12-10 10:34:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!