AS3 Library for the WordPress API
I’m sorry to say that I no longer have the time nor the inclination to update this library – please feel free to download for any personal, commercial, or other use, but I will no longer be updating this page or the source code.
Hi there.
I’ve developed an (almost) fully featured ActionScript library for WordPress XML-RPC, that any flash developer can use to build flash front-ends for WordPress managed sites. The library builds on the work of Akeem Philbert (who developed this excellent XML-RPC library), and is designed to make connecting Flash with WordPress easy and straightforward.
About the library
I developed this for the simple reason that there didn’t seem to be one available. I wanted a WordPress service that could make sensible method calls in an easy way rather than having to pass everything through XMLRPCObject, and I wanted results that would be strongly typed versions of the XML-RPC results, with separate event types for each call. My WPService class does exactly that, and I hope some of you out there find it useful.
Download: » version 1.01
Requirements
- Akeem Philbert’s XML-RPC Library (included in the download)
- The Flex2 SDK
Documentation
Documentation in ASDoc format is included in the download and is also online here:
AS3 WordPress Documentation
Usage
The use of this library is intended to be straightforward – there are three basic steps:
- Create a
WPService - Add event listeners to listen for server results
- Make a method call using one of the service method groups
1. Create a WPService
var service:WPService = new WPService(myBlogUrl, myUserName, myPassword);
2. Add event listeners
service.addEventListener(WPServiceEvent.GET_RECENT_POSTS,getRecentPostsHandler);
3. Make a service call using one of the service method groups.
service.posts.getRecentPosts();
The WPService class has methodgroups for making calls relating to blogs, posts, pages, categories, tags, comments and authors, eg: service.posts.getRecentPosts(); will make a call to wp.getRecentPosts using the blogUrl, username and password you used to initialize the service.
A simple example
This class will get the 20 most recent posts from your blog and trace their details to the output window.
You will need to replace URL, USER, and PASS with your correct details.
package{ import flash.display.Sprite; import com.absentdesign.core.webapis.events.ServiceEvent; import com.absentdesign.core.webapis.wordpress.events.WPServiceEvent; import com.absentdesign.core.webapis.wordpress.*; public class Example extends Sprite{ private var service:WPService; private static const URL:String = "http://path.to.your.blog/"; private static const USER:String = "your_user_name"; private static const PASS:String = "your_password"; public function Example(){ service = new WPService(URL,USER,PASS); service.addEventListener(WPServiceEvent.GET_RECENT_POSTS, getRecentPostsHandler); service.posts.getRecentPosts(20); } protected function getRecentPostsHandler(event:ServiceEvent):void{ traceData(event.data); } protected function traceData(data:*):void{ if(data is WPStruct){ trace(data.getDump()) } else if(data is Array){ for each(var struct:WPStruct in data){ trace(struct.getDump()) } } else{ trace(struct); } } } }
Licence
This library is free to use, modify and distribute under a New BSD licence. If you do find it useful, please let me know at reuben[at]absentdesign[dot]com, or leave a comment below.
If you use the library for a commercial project (or just really like it), you may even want to consider a donation:
A caveat
There are a few things in the WordPress XML-RPC spec that were not included in the library (most notably wp.getOptions and wp.uploadFile), but these may be included in future releases. This is only version 1, and it has only been tested by me so far. Some things are bound to go wrong – if you have a problem with the library then please let me know!
Changelog
v1.01 : updated Categories.as to include setPostCategories method (mt.setPostCategories).
Awesome idea and what i needed right now:)
Does it work with flash ide?
I tested it and got several errors
For example:
1017: The definition of base class AbstractService was not found.
Sorry David, it doesn’t work with the Flash IDE as Ak33m’s XML-RPC Lib requires a few of the Flex SDK compiled classes – unfortunately I couldn’t get around this.
too bad:(
ok thx
Great! Thanks a lot. This is really good work.
Me again … Works great so far.
Just want to ask if it’s possible to post into a specific category (service.posts.newPost)? I can grab the existing categories, but seems like there’s no “categories” property in the Post Class.
Thanks! Florian
Hi Florian
Thanks for picking that up – I actually forgot to add the mt.setPostCategories method to the Categories class.
There is no “categories” property in any of the Post calls in XML-RPC wp but once I’ve fixed the Categories class you will be able to call service.categories.setPostCategories(postId:int,categories:Array) to update the categories on a particular post.
I’ll add the setCategories method upload a new version later today.
I’ve updated the library to include the categories.setPostCategories method now – let me know how you go.
Thanks for the update, works perfect
By the way: I just want to mention that here’s a fix for the classes of the XML-RPC library in order to use it with Flex 3 + 4: http://ak33m.com/?p=50
Hi Reuben,
is there a possibility to check if the connection to a blog could be established? Is there an error event if there’s problem (for instance a wrong url, username or password).
Thanks, Florian
Thank you very much! I will use it to build a flex blog site based on WordPress.
Hi Reuben,
this is awesome.
I haven’t tried it out yet, but i wonder if it is possible to do a search from flex?
Thanks!
@ Florian – sorry, the WP XML-RPC spec is quite limited and does not return specific errors – I’ll look into implementing better error handling on the flash side in a future release.
@ Shisang Lu – thanks!
@ Tizzle – As far as I can see, the WP XML-RPC spec does not have any search functionality built in – the only way I can think to do it would be to call posts.getRecentPosts(9999) and then perform a search on the Flex side.
Thanks for all the heavy lifting! I’ll check it out as well, sounds really promising…
@ charlie – no problem – if you do use it for something interesting let me know, I’d love to see what people use it for…
Great work you’ve done!
But I’m ambarassed with these strings:
private static const URL:String = “http://path.to.your.blog/”;
private static const USER:String = “your_user_name”;
private static const PASS:String = “your_password”;
So anybody can decompile my flash and mess with my password?
It’s not good.
Is there any way to make it more secure?
The best way is to make me enter login/password any time flash-app strts working.
And then sending this info encrypted.
@Roma – thanks.
I just set these strings up as a simple example to get you up and running – you don’t have to hard-code the password by any means – there is no reason you couldn’t build a different interface that would create the WPService and login once the user had entered their details.
I’m not sure how you’d go about sending the info encrypted though – the WP XML-RPC interface (as far as I know) isn’t set up to handle encrypted data.
hi, i’m pretty excited to have found this, but i have some questions.
so, it seems like if you want to retrieve posts, you can only get a particular post by its ID or get a number of recent posts ? is there no way to pass in parameters, such as category ?
thanks
Thanks for this work ! very cool tool, and realy pretty code !
But i have a problem with the new method : setPostCategories, i call it just after created a post, but it does’nt work. The event is fired WPServiceEvent.SET_POST_CATEGORIES
and “event.data” return “true” …
I did’nt know why ?
any ideas ?
thanks again.
@ brian – thanks – unfortunately, no, you can’t get an array of posts with additional params – the WP XML-RPC interface only has the two calls (by ID or by number) – it is quite limited.
@ thomas – This is actually the correct response based on the mt.setPostCategories call (which Word Press uses) – It is my documentation that is wrong – see here: http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtsetpostcategories.html
When you call setPostCategories, you will have to call getPost again to check that your categories have been updated correctly, the categories are not returned in the SET_POST_CATEGORIES event – sorry about the confusion.
ok But my categories are no updated correctly and i don’t know why
i try it :
var cats : Array = new Array();
for ( var i in wpcategories.selectedItems )
{
var a : Object = new Object();
a.categoryId = int( (wpcategories.selectedItems[i] as Category).categoryId );
cats.push( a ) ;
}
_wpservice.categories.setPostCategories( postId, cats );
I check postId and categoryId and there seem good, I check on my blog and the categoryId exists …
I’m lost
Do you have any example ?
Thanks in advance.
Find the solution, we should pass a Category Object to setPostCategories ( postId, Category)
was hard,
thanks again for this great lib !
[...] WordPress XML-RPC API http://blog.absentdesign.com/?page_id=22 [...]
[...] WordPress XML-RPC API http://blog.absentdesign.com/?page_id=22 [...]
Great work, very useful!
I’m having a bit of difficulty using getComments. The params I pass seem to be ignored and the last 10 messages for the blog are always returned regardless of what is passed in.
In the example below there are more than 10 comments to post#0 but only the last 10 comments (some of which belong to other posts) get returned.
var serv:WPService = new WPService(Url, User, Pass); serv.addEventListener(WPServiceEvent.GET_COMMENTS, gotNewWPComments); serv.comments.getComments(0,”",0,999999);
Update to the last post…
After debugging and reading http://code.google.com/p/as3-rpclib/issues/detail?id=5 (which isn’t quite right), I’ve found out where the problem was.
A Struct (which is optional for getComments and other wp methods – http://codex.wordpress.org/XML-RPC/wp.getComments) is not created properly.
THE FIX: Replace the last ‘else if’ block from the method encodeObject inside XMLRPCSerializer with this…
else if (tobject is IXMLRPCStruct)
{
//txmllist = encodeStruct(tobject.getPropertyData()); – removed as struct was not being created properly. N.Gossage 29/Jul/09
txmllist = encodeStruct(tobject);
}
Another bug fix for getComments. Inside Comments.as, the method getComments has this line…
struct.postId = postId;
it should be…
struct.post_id = postId;
This change should also be applicable to other methods where the struct contains a post_id.
Am I doing something wrong?
I tried the library with Flex SDK 2, 3 and 4 and I always get a 1017 error:
The definition of base class AbstractService was not found.
Hi,
do u have a version for Flex SDK 3.2, 3.4, 4 ???
I hava a error by 3.2:
override public function setCredentials (username:String,password:String):void
{
this._gateway.setCredentials(username,password);
}
override public function setRemoteCredentials (username:String,password:String):void
{
this._gateway.setRemoteCredentials(username,password);
}
in this both lines is a error what not allowed in 3.2 but i don’t know why…
best regards
very nice work!!!!!!!
Great Work!
I am hoping to use this library for a WordPress MU/Buddypress installation. Does this framework support WordPress MU and Buddypress?
ok I got it to work;
I saw a comment about getting errors if something goes wrong. My solution is putting at the constructor of the com.absentdesign.core.webapis.events.ServiceEvent Class the following:
if (data.faultString != undefined){
trace(“FAULT STRING”);
trace(data.faultString);
}
I am trying now to write an ERROR if the xmlrpc.php URL is wrong.
greets
[...] WordPress XML-RPC API http://blog.absentdesign.com/?page_id=22 [...]
Hi nigelg,
I had the problem with getting comments a for selected post.
so, with your fixes i was able to get it running correctly.
Thank you very much!
and oh nigelg,
after i made those modifications for the classes,
now i can’t add comments to post, actually it added the comment, but the content is blank.
and solution for this?
well done! always wanted to do a wordpress blog in flash.
managed to compile it and connect properly.
was getting a run-time error using Flex 3.0 SDK,
although if i used Flex 3.1 – 3.4 SDK, it worked fine.
any idea what this could be?
error message below as a reference.
Error: No class registered for interface ‘mx.resources::IResourceManager’.
at mx.core::Singleton$/getInstance()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\Singleton.as:111]
at mx.resources::ResourceManager$/getInstance()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\resources\ResourceManager.as:83]
at mx.rpc::AbstractService()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AbstractService.as:92]
at com.ak33m.rpc.core::AbstractRPCObject()[/Users/lukasz/Sites/flex3/Worpress/src/com/ak33m/rpc/core/AbstractRPCObject.as:79]
at com.ak33m.rpc.xmlrpc::XMLRPCObject()[/Users/lukasz/Sites/flex3/Worpress/src/com/ak33m/rpc/xmlrpc/XMLRPCObject.as:51]
at com.absentdesign.core.webapis.wordpress::WPServiceRequest()[/Users/lukasz/Sites/flex3/Worpress/src/com/absentdesign/core/webapis/wordpress/
I was wondering if there was any more news/work done on the security for:
private static const USER:String = “your_user_name”;
private static const PASS:String = “your_password”;
I ask because I’d love to implement this but as someone else mentioned above, I’m not a fan of the idea of having people able to decompile the website and find that information sitting in my code.
Thanks.
@Nuwan – Looking at my code I think I hit the same problem after my last change too so I added this block above my last change in the same place (the method encodeObject inside XMLRPCSerializer)
//added to enable posting new comments – N.Gossage 29/Jul/09
else if (tobject is com.absentdesign.core.webapis.wordpress.Comment)
{
txmllist = encodeStruct(tobject.getPropertyData());
}
@everyone – This is a fix to the comments part of the API, read my previous comments on this page to understand the context of this message.
[...] WordPress XML-RPC API http://blog.absentdesign.com/?page_id=22 [...]
Hey Reuben, thanks for sharing your work, it’s really neat.
One thing I can’t figure out how to do is to access the categories of the posts returned. For example, if I want to retrieve the 20 most recent items from the ‘news’ category of my wordpress blog, I have to retrieve X amount of recent posts, then individually check the categories each one has using getPostCategories(). Each post has to have an individual http request sent which is quite slow and these must be done one-at-a-time so the app knows which request is being responded to (the post id is not returned with the categories).
When my list of recent posts is returned the posts do not have a category property.
Is there a way I can request posts of a certain category or access the category of returned posts?
I’m sure I must be missing something obvious here!
Thanks for any assistance
Alistair
[...] XML-RPC There are people suggesting to use the XML-RPC connector to get at your data. For me this turned out to be a dead end. The XML-RPC is designed for creating alternate ways to [...]
Hi,
With regards to security, is there any way that we can pass values from a php file to use in the flash package or this is still the same as having them embedded??
Thanks
[...] while ago I stumbled upon this nice ActionScript 3.0 library to work with the WordPress XML-RPC calls. It does extends the more abstract XML-RPC AS3 [...]
[...] while ago I stumbled upon this nice ActionScript 3.0 library to work with the WordPress XML-RPC calls. It does extends the more abstract XML-RPC AS3 [...]
Great library. Thanks a lot! That is what I was looking for.
Only one thing — can it be used to send data? I mean writing and posting to blog through flash-interface?
As I can see (may be mistaken) it obly retreives data.
Thanks.
I have just 5 weeks with Flex on my back and even I got this working! Absolutely great!
Thank you.
Btw. To get this working in flex 3, have a look at this article: http://jonniespratley.com/2008/10/02/adobe-flex-using-xml-rpc/ Just change the setCredentials things the way the article says.
Hi,
I am trying to make the above example to work, my project compiles without errors but I don’t see any result in Output Window
“(fcsh)Build succeeded
Done (0)
[Capturing traces with FDB]
“
Hey looks like a great script, and would love to get it to work, but I seem to be getting errors every time I to compile the script:
1017: The definition of base class AbstractService was not found.
1045: Interface IMXMLSupport was not found.
1020: Method marked override must override another method.
1020: Method marked override must override another method.
1020: Method marked override must override another method.
1020: Method marked override must override another method.
1020: Method marked override must override another method.
Am I doing something really wrong? I just tried executing your example and got these!
If any one know what this might be, that would be great!
Thanks for your help guys
@VLAD:
I have the same problem in the Flash IDE, so if you look in the other comments it says that it doesn’t actually work in Flash but only in FLEX
after some searching we found that it is very important that inside your WordPress Admin console you need to ENABLE “WordPress, Movable Type, MetaWeblog en Blogger XML-RPC publishing protocols” under Settings > Writing.
otherwise i will not connect.
also: thank you for developing this, it works like a treat!
got these errors as well. trying to compile with flashbuilder with flex4 sdk.
1017: The definition of base class AbstractService was not found.
1045: Interface IMXMLSupport was not found.
1020: Method marked override must override another method.
1020: Method marked override must override another method.
1020: Method marked override must override another method.
1020: Method marked override must override another method.
1020: Method marked override must override another method.
Great bit of coding Reuben, thanks for sharing. I have one thing that I’m particularly worried by though: the username and password can quite easily be picked up using Charles or other similar software. As far as I can see within WordPress, you have to set the user that is retrieving data to be at least a editor, meaning that if someone had the know-how and wanted to screw up your wp, they’d have absolutely no problem. Hopefully I’m wrong with this and there’s a nice easy route around it?
@dirtyFlasher, @randiD – I haven’t really looked at options here – you could try setting up a php file that passed the values in to the flash using a POST call, but I’m not sure if this would provide better security or not – unfortunately the WP api requires a user/pass with every call so the flash needs to know it somehow…
@everyone else – sorry I haven’t posted any bug fixes, or responses to your queries, I haven’t had any time to work on this library for months… I’ll get back on it some time soon.
Following previous comment, thought I’d feed back a solution that works for us with regards to security. We’re only using WP as a CMS to feed data to our site, so instead of passing username and password with every call to XMLRPC we’re going to remove these from the calls and hard-code the username and password in the xmlrpc.php file in the WP install and remove/disable all edit and delete functions from within there. Obviously if you were going to be doing updates from Flash then you’d not want to go this route as anyone would be able to do, so you’d have to look down the route of encryption but seems like this is the easiest and safest solution for us at the moment.
Hopefully that helps anyone stumbling across this blog looking to do the same thing.
[...] really like to thank everyone linked above for helping with this project and most especially Reuben Stanton of Absent Design for his work on an XML-RPC package with full documentation to let Flash “talk” to [...]
hy,
thanks for this nice class.
Is it possible to request posts for one tag / category.
I think getRecentPosts is nice, but when I want to select posts for eg. the tag ‘adobe’ I didn’t see any way.
Is there a function / possibility.
I have also looked at the xmlrpc documentation, but I missed this feature.
Do you have a hint for me?
Thanks
[...] http://blog.absentdesign.com/?page_id=22 [...]
[...] WordPress XML-RPC APIhttp://blog.absentdesign.com/?page_id=22 [...]
ru/skachat-video-skrytaya-kamera-v-dushe-. Все девчата обладают если не отличными, то чрезвычайно близкими к идеалу фигурами. На данный момент он указывает цену в 30 российских рублей на номера 3649 и 1171. html – порна скрытая камераhttp://mselez.
it supports brand new wordpress 3.0?
I don’t know from where to start, what should I do with Flex SDK and the classes? Can anyone help me?
Between us speaking, I would ask the help for users of this forum.
Hi…
how can I get the tags for one post.
So …. I need the same like getPostCategories for Tags.
Is there a solution ?
Thanks,
Benjamin