Invoking OpenX api from Flex
Posted by cornel | Filed under Flex, OpenX
For the last several months I was playing with OpenX, an open source ad server written in PHP. You can interact with OpenX in two ways: first by using the admin graphical interface, second by using API calls – most of the UI functionality can be programmatically reproduced.
OpenX is exposing its API through XML-RPC and they have a couple of examples on their website how to invoke the API from PHP, Java and Ruby. In my case I was trying to display some statistics without going through a middleware, so I started to investigate how can I do it from Flex. It turned out to be quite easy – one can use the AS3 RPC written by Akeem Philbert, with a small modification. The following steps should be done:
a) download the source code of the library from this location (http://code.google.com/p/as3-rpclib/)
b) you have to fix a small issue in the class com.ak33m.rpc.xmlrpc. XMLRPCObject (compatibility issue between SDK’s). The overloaded methods setCredentials and setRemoteCredentials should receive another parameter, called charset.
c)create the objects mapping the OpenX structures (advertiser, campaign, zone etc) and invoke the exposed methods
I did these steps and I created this Flash Builder project – you can import it into your workspace and change the file ServerConfig.as accordingly.
In my example I have just a couple of operations like login, displaying and creating advertisers. It can easily be extended in order to support the whole OpenX api.
Next post on OpenX will be about displaying the ads on your website, from Flash and HTML.
April 28th, 2011 at 2:49 pm
Hi Cornel,
I enjoyed reading your blog post and I’d love to learn more about your next steps in exploring the OpenX API for your Flex development.
Regards, Erik Geurts – OpenX specialist
April 28th, 2011 at 3:30 pm
Thanks Erik
March 18th, 2012 at 4:46 pm
Hello Cornel,
I went through this. Its very useful. But I need some help
Now, I am trying to write a jsp application which will establish the xmlrpc connection with openxapi and return the values. I am using openxapi v1
Here I get the dates through a datepicker and then convert to date format:
`String dateStr = request.getParameter(“datum1″);
SimpleDateFormat formater = new SimpleDateFormat(“dd-MM-yyyy”);
Date result1 = formater.parse(dateStr);
String dateStr2 = request.getParameter(“datum2″);
SimpleDateFormat formater2 = new SimpleDateFormat(“dd-MM-yyyy”);
Date result2 = formater2.parse(dateStr2);`
Then I call the service provided by openxapi (Advertiser Daily Statistics)
(sessionID, advertiserID, from date, to date)
`Object[] objects1=(Object[])client.execute(“advertiserDailyStatistics”,new Object[]{sessionId,3,result1,result2});`
This code is not returning anything
Tried printing the value or even the length of the object, but no success
Let me know if you need more info from me
Pl help with this weird issue
Thanks