I have a Wordpress blog together with a little Android App, developed by myself. Now I want to expand my app a little. My goal is to implement a kind of live ticker. The function is as follows:

On my blog there is a page or a post with a fixed (never changing) title. The comments on this page I'll get over the REST API as JSON and parse this JSON in my app to display the comments. So far so good, this is no problem and has already been implemented several times by myself.

Where it now rakes: Now I need to implement the option to post a new comment from my app via JSON over the REST API. What does the JSON have to look like, that I need to send to my blog and how can I authenticate?

That is what I have:

String nonceResponse = makeGetRequest("http://vorwaerts-spoho.de/wordpress/api/get_nonce/?controller=auth&method=generate_auth_cookie");
JSONObject obj1 = new JSONObject(nonceResponse);
nonce = obj1.getString("nonce");

String jsonResponse = makeGetRequest(String.format("http://myblog.de/wordpress/api/auth/generate_auth_cookie/?nonce=%s&username=myname&password=mypw", nonce));
String cookie = new JSONObject(jsonResponse).getString("cookie");               
makeGetRequest(String.format("http://myblog.de/wordpress/api/submit_comment/?cookie=%s&post_id=193&name=myname&email=mymail@gmail.com&content=test1234", cookie));

This works nearly fine, as my cookie looks like this:

{"status":"ok","cookie":"myname|1412347657|kq1Hiat3D4142fJeL8FuggFpQrxwPVoxXoqLW3Wamnd|d20bba98083e8a5b83b76b9357ca3eb881b82470965f88f84ec99d2e7a2cc6f8","user":{"id":3,"username":"myname","nicename":"myname","email":"mamail@gmail.com","url":"","registered":"2014-09-19 14:21:35","displayname":"my name","firstname":"my","lastname":"name","nickname":"myname","description":"","capabilities":"","avatar":null}}

But I am still not able to sumbit the comment in the last step. It seems as if there is a problem with the pipe (|) in my url. So I hope you can help me at this point?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.