Archive

Posts Tagged ‘social bookmarking’

Save bookmark on delicious using flex

May 15, 2009 Leave a comment

Hi, today i come up with interesting blog which explains about how to invoke api methods from flex application. Before that, i want to tell why do we need to access api methods ?. If you ever need to store or retrieve data from the third party server through any client application then we can make it possible with the help of third party api. If you want to access any third party api, you must be aware of certain things.

They are follows

  1. Which api method you are going to access ?
  2. What is the URL of the api method you need to access ?
  3. What are the parameters the api method expects ?
  4. What kind of data the api method returns ?
  5. What can you do with the returned data ?

If you can answer to the questions above when you try to access then nothing will stop you. Once you have understood what you want to do, what you are going to pass as an input and what it gonna return then you have done more than 50% of the work. the rest of the thing is coding which is very easy if you aware about flex nothing more needs.

Now i am going to add a new bookmark in my delicious account, for that i have to know certain details i have mentioned above. To know those details i have to go developers section in delicious API where you can see the available api methods in delicious and you can know about each api method HTTP URL, parameters need to pass and the data it returns. Check out this below URL and explore the delicious  api methods. http://delicious.com/help/api. now i know which method i need to access ie posts/add and all those stuff i need to know.

Steps to create flex application which adds new post in your delicious account

  • create mxml application in flex builder
  • create httpservice instance and give an ID to the httpservice
  • specify the URL of the httpservice
  • Declare the event handler function for result and fault property of httpservice
  • specify the result format of httpservice
  • pass the parameters of the httpservice via <mx:Request> which is declared inside <mx:HttpService> ie httpservicee instance
  • define event handler functions which you have declared in result and fault property of httpservice
  • Bind the user input data to the request parameters of httpservice.
  • invoke httpservice and it will prompt you to sign in your delicious account if you are not logged in already.

Once you have successfully added new bookmark, it will return xml node ie <result code=”done”/>, else it will return <result code=”something went wrong”/>.

Code


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<!&#91;CDATA&#91;

import mx.controls.*;
import mx.rpc.events.*;

&#91;Bindable&#93;public var varUrl : String;
&#91;Bindable&#93;public var desp : String;
&#91;Bindable&#93;public var tagName : String;

public function resultHandler(event :ResultEvent):void
{
Alert.show(event.result.@code);
}

public function faultHandler(event :FaultEvent):void
{
Alert.show(event.fault.message);

}

&#93;&#93;>
</mx:Script>

<mx:HTTPService id="myService" url="https://api.del.icio.us/v1/posts/add?" fault="faultHandler(event)"
resultFormat="e4x" result="resultHandler(event)" showBusyCursor="true" >
<mx:request xmlns="">
<url>{urlInput.text}</url>
<description>{description.text}</description>
<tags>{tags.text}</tags>
</mx:request>
</mx:HTTPService>

<mx:Panel title="Bookmark on delicious" backgroundAlpha="0.2" paddingLeft="20" paddingRight="20" paddingTop="20" paddingBottom="20">
<mx:Form>
<mx:FormItem label="URL">
<mx:TextInput id="urlInput" />
</mx:FormItem>
<mx:FormItem label="Description" >
<mx:TextInput id="description" />
</mx:FormItem>
<mx:FormItem label="Tags">
<mx:TextInput id="tags" />
</mx:FormItem>
<mx:Button label="Save bookmark" click="myService.send()" />
</mx:Form>
</mx:Panel>

</mx:Application>