• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Posting to wordpress from android app

 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys. Is there is a way to post comments (or even posts) in Wordpress blog using Json, for example?
Now I know how to retrieve data using json, but not to post.

Can't find any useful example.
 
Paul Clapham
Sheriff
Posts: 21566
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there's a WordPress app for Android so it must be possible. I don't know if it has a published API though.

I also haven't tried the app.
 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Well, there's a WordPress app for Android so it must be possible. I don't know if it has a published API though.

I also haven't tried the app.


Oh, there is. There is a source code too, but it's really messy as for beginner.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you give a shot following code.



And this is HttpsClientBuilder class for HTTPS web sites (Note: This code is not belong to me. I found somewhere else)

 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wordpress exposes an XML based API to post blogs or comments. This is inbuilt and does not need any plugins to support it.
A JSON interface would require some kind of 3rd party plugin (I had a quick look in Wordpress 4 source code, and I could find no inbuilt JSON API).

If XML is ok with you, then I can give you information on how to do so from Java, since I've written a java desktop application for my own use that does exactly that.
 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ibrahim Yener, thank you! I'll try that.
 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik Shiraly wrote:Wordpress exposes an XML based API to post blogs or comments. This is inbuilt and does not need any plugins to support it.
A JSON interface would require some kind of 3rd party plugin (I had a quick look in Wordpress 4 source code, and I could find no inbuilt JSON API).

If XML is ok with you, then I can give you information on how to do so from Java, since I've written a java desktop application for my own use that does exactly that.


Actually in my blog there is a Json plugin but if you can share how to do without it, it would be good!
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually in my blog there is a Json plugin but if you can share how to do without it, it would be good!

The Wordpress official API is called XML-RPC API. It's documentated farely well on the wordpress developer site.

If you're not familiar with it, then XMLRPC is a somewhat outdated web service protocol. All the requests and responses are encoded as XML snippets.
The RPC in the name (RPC=Remote Procedure Call) hints at the contents of those XML requests and responses. Basically, the requests have a method name and a list of arguments.
The responses contain a return object or an exception object. Both requests and responses have to follow a particular XML schema mandated by the protocol.

IIRC, XMLRPC is enabled by default on all Wordpress sites above version 3, but used to be disabled by default in earlier versions. If it's disabled, enable it from your WP admin portal.

On the developer site, notice the 2 APIs "wp.newPost" and "wp.newComment" - those are the two you'd need to publish new posts or comments.

For forming schema compliant XMLs, download the Apache XMLRPC library.
In your project, add xmlrpc-client.jar, xmlrpc-common.jar, ws-common-util.jar and commons-logging.jar to classpath.

The XMLRPC endpoint is typically "http://[your-blog-url]/xmlrpc.php". However, some people (me!) change this to avoid spam bots. So if you're writing a general purpose tool that can be used by anybody, then you might want to provide a way for user to enter the endpoint URL.

Code for publishing a new post goes like this:


Similar code for wp.newComment. Its arguments are documented here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic