• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Posting to wordpress from android app

 
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 27590
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 202
Android PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)

 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Are you here to take over the surface world? Because this tiny ad will stop you!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic