error response with Json request to Disqus on Volley (Android) -
i trying connectt disqus
their api
(specifically calling post https://disqus.com/api/oauth/2.0/access_token/
)
i using jsonobjectrequest
volley
library network calls. response consistently error code 400:
11-19 12:48:17.119: e/volley(16124): [107902] basicnetwork.performrequest: unexpected response code 400 http://disqus.com/api/oauth/2.0/access_token/
i have tried proxy request in charles see more info, , got error message:
and request recorded charles (as can see did add parameter grant_type
):
i calling same request in ios version of app, , using same keys , information, , works there. why assume problem somewhere in code, perhaps in way add/encode/not encode parameters... code use send request:
string url = "http://disqus.com/api/oauth/2.0/access_token/"; jsonobject jsonobj = new jsonobject(); try { jsonobj.put("grant_type", "authorization_code"); jsonobj.put("client_id", publickey()); jsonobj.put("client_secret", secretkey()); jsonobj.put("redirect_uri", redirecturl()); jsonobj.put("code", code); } catch (jsonexception e1) { e1.printstacktrace(); } jsonobjectrequest jsonobjreq = new jsonobjectrequest(method.post, url, jsonobj, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { try { string refreshtoekn = (string) response.get("refresh_token"); string accesstoekn = (string) response.get("access_token"); string stam = refreshtoekn+accesstoekn; } catch (jsonexception e) { e.printstacktrace(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d("error: " + error.getmessage()); } }); volleycontroller.getinstance().addtorequestqueue(jsonobjreq);
the call falls onerrorresponse
i have tried use stringrequest
, add parameters in url
no successes
so managed work, love if explain why solution works. basically, instead of using jsonobject
, passing jsonobjectrequest
used stringrequest
, overrode getparams
.
was wrong trying send post request jsonobjectrequest
?
this entire solution:
string url = "http://disqus.com/api/oauth/2.0/access_token/"; stringrequest stringreq = new stringrequest(method.post, url, new response.listener<string>() { @override public void onresponse(string response) { string string = response; } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d("error: " + error.getmessage()); } }) { @override protected map<string,string> getparams(){ map<string,string> params = new hashmap<string, string>(); params.put("grant_type", "authorization_code"); params.put("client_id", publickey()); params.put("client_secret", secretkey()); params.put("redirect_uri",redirecturl()); params.put("code", code); return params; } @override public map<string, string> getheaders() throws authfailureerror { map<string,string> params = new hashmap<string, string>(); params.put("content-type","application/x-www-form-urlencoded"); return params; } }; volleycontroller.getinstance().addtorequestqueue(stringreq);
Comments
Post a Comment