XML-RPC
XML-RPC is the second request format supported by Flickr. XML-RPC uses HTTP as the transport and XML for encoding. In XML-RPC, the method parameters are wrapped in a XML document and POST-ed to the XML-RPC endpoint, in this case http://api.flickr.com/services/xmlrpc/.
A XML-RPC request will have this format:
<methodCall>
<methodName>flickr.test.echo</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>api_key</name>
<value><string>..your API key..</string></value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
If the method takes more than one parameter, you will have to repeat the <member> structure for each parameter; you can find detailed instructions regarding the packaging of complex datatypes at www.xmlrpc.com.
Here is how to implement this call in Actionscript:
var request:XML;
var response:XML;
request=new XML();
response = new XML();
response.onLoad=function(success:Boolean){
trace(success);
trace(this.toString());
}
request.xmlDecl = '<?xml version="1.0"?>';
request.parseXML("<methodCall><methodName>flickr.test.echo</methodName><params>
<param><value><struct><member><name>api_key</name><value>..your API
key..</value></member></struct></value></param></params></methodCall>");
request.sendAndLoad("http://api.flickr.com/services/xmlrpc/", response);
Since this is a HTTP POST operation, I have to use the sendAndLoad method of the XML object.
Developer Matt Shaw is behind an open source project that provides a XML-RPC library for Actionscript; an introduction can be found at http://xmlrpcflash.mattism.com/, or you can download the library (more details can be found here). Using this library, the call to the echo function shown above would look like this:
import com.mattism.http.xmlrpc.Connection;
import com.mattism.http.xmlrpc.ConnectionImpl;
onLoadListing = function( response:Array ){
trace("Found the following objects:");
var i:Number;
for (i=0; i<response.length; i++){
trace(i+". "+url+response[i]);
}
};
var url:String = "http://api.flickr.com/services/xmlrpc/";
var c:Connection = new ConnectionImpl();
c.setUrl(url);
c.onLoad = onLoadListing;
c.addParam( { api_key:'...your API key...' }, "struct");
c.call("flickr.test.echo");