Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve posts from a WordPress Blog in an Android App?

I'm trying to develop an Android app for browsing a Wordpress-powered blog I own. I'm trying to figure out how to retrieve posts and other information from the blog to display in the app. I've looked all over but I feel completely lost. Is this something that can be done entirely in Java/XML? If so, how?

Thank you!

like image 268
Argus9 Avatar asked Aug 19 '12 06:08

Argus9


People also ask

Can you use WordPress on Android?

In one word: yes. WordPress's mobile apps for Android and iPhone allows users to create posts, upload photos, moderate comments and more.

Can I blog on WordPress on my phone?

WordPress for AndroidYou can use the mobile app to create, edit, and publish posts, manage your media, delete or approve comments, and track your site's traffic and trends. Later versions of the plugin also include the ability to customize your Theme and Menu settings.


1 Answers

Yes, it can be done.

One way is to use the xml-rpc api. Wordpress blogs have an xml-rpc api(which you need to enable on the Wordpress blog under "Settings - Writing"). You will also need to create a user on the blog, which you give at least read access, and for which you include the credentials in your app. From then on, you can do xml-rpc calls to your Wordpress blog(s).

If using this xml-rpc api is an option, take a look at this Java lib: http://code.google.com/p/wordpress-java/

You can get the blogposts using this lib like this:

String username = args[0];
String password = args[1];
String xmlRpcUrl = args[2];
Wordpress wp = new Wordpress(username, password, xmlRpcUrl);
List<Page> recentPosts = wp.getRecentPosts(10);

Also, the official Wordpress Android app is open source. Instructions to get it are at: http://android.wordpress.org/development/ You could use this source code as a starting point and adapt it to your needs.

Note that you can only use the xml-rpc api when you have a user with read access. If you do not have the credentials of a user with read access, you can't get the posts using the xml-rpc api. Fetching the rss feed and parsing the rss feed with some java lib would probably be your best bet then(check http://www.vogella.com/articles/RSSFeed/article.html on how to read an rss feed using Java).

like image 127
Integrating Stuff Avatar answered Nov 01 '22 17:11

Integrating Stuff