Posted By

Whiteagle on 09/23/10


Tagged

on twitter Flex bitly share


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

bobbym245


Share on Twitter (with Bit.ly shortned link) [FLEX]


 / Published in: ActionScript 3
 

URL: http://www.digitalwks.com/blogs/diogo-raminhos

  1. //Twitter/Bit.Ly Share Imports
  2. import flash.net.navigateToURL;
  3. import mx.rpc.events.ResultEvent;
  4. import mx.rpc.xml.SimpleXMLDecoder;
  5. import mx.utils.ObjectUtil;
  6.  
  7.  
  8. //Twitter/Bit.Ly Share Vars
  9. private var bitLyLoader:URLLoader;
  10.  
  11.  
  12. /*
  13.  * Call this function to share on twitter, passing your url trough bit.ly!
  14. */
  15. private function twitterShare(articleUrl:String):void
  16. {
  17. // Insert your bit.ly account name & API Key bellow
  18. var bitLyApiUrl:String = "http://api.bit.ly/v3/shorten?login=ACCOUNT NAME&apiKey=API KEY&longUrl="+articleUrl+"&format=xml";
  19. var bitLyApi:URLRequest = new URLRequest(bitLyApiUrl);
  20. bitLyLoader = new URLLoader(bitLyApi);
  21. bitLyLoader.addEventListener(Event.COMPLETE, bitLyFinished);
  22. }
  23.  
  24. /*
  25. * Get the short link & post to twitter
  26. */
  27. private function bitLyFinished(event:Event):void
  28. {
  29. // Lets decode the bit.ly answer!
  30. var getLink:XMLDocument = new XMLDocument(bitLyLoader.data);
  31. var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
  32. var bitLyLink:Object = decoder.decodeXML(getLink);
  33. // Insert your message bellow! Use %23 for trending topics! (Example: %23DigitalWorks)
  34. var URL:String = "http://twitter.com/home?status=Currently reading "+bitLyLink+" %23DigitalWorks";
  35. navigateToURL(new URLRequest(URL), '_blank');
  36. }

Report this snippet  

You need to login to post a comment.