{"id":253,"date":"2009-07-09T07:44:52","date_gmt":"2009-07-09T14:44:52","guid":{"rendered":"http:\/\/www.nayansavla.com\/blog\/?p=253"},"modified":"2010-08-01T18:09:12","modified_gmt":"2010-08-02T01:09:12","slug":"posting-to-twitter-from-flash-using-tiny-url","status":"publish","type":"post","link":"https:\/\/www.nayansavla.com\/blog\/?p=253","title":{"rendered":"Posting to Twitter from Flash using Tiny Url"},"content":{"rendered":"<p>I had to find a way to post a link to twitter directly from Flash. Twitter has its own API but then they expect us to collect username and password.<br \/>\n&nbsp;<br \/>\nIf you don&#8217;t want to collect usernames and passwords on your site and still manage to post stuff to twitter directly there is a way to do. Since I wanted a tiny url link included as well so had to integrate Tiny Url along with twitter.<br \/>\n&nbsp;<br \/>\nIt turned out to be really easy and here is how,<br \/>\n&nbsp;<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:435px;height:300px;\"><div class=\"actionscript codecolorer\"><span class=\"kw3\">import<\/span> flash.<span class=\"me1\">events<\/span>.<span class=\"me1\">MouseEvent<\/span>;<br \/>\n<span class=\"kw3\">import<\/span> flash.<span class=\"me1\">net<\/span>.<span class=\"me1\">navigateToURL<\/span>;<br \/>\n<span class=\"kw3\">import<\/span> flash.<span class=\"me1\">net<\/span>.<span class=\"me1\">URLLoader<\/span>;<br \/>\n<span class=\"kw3\">import<\/span> flash.<span class=\"me1\">net<\/span>.<span class=\"me1\">URLRequest<\/span>;<br \/>\n<span class=\"kw3\">import<\/span> flash.<span class=\"me1\">net<\/span>.<span class=\"me1\">URLLoaderDataFormat<\/span>;<br \/>\n<br \/>\nshareBlog.<span class=\"me1\">addEventListener<\/span><span class=\"br0\">&#40;<\/span>MouseEvent.<span class=\"me1\">CLICK<\/span>,postToTwitter<span class=\"br0\">&#41;<\/span>;<br \/>\n<br \/>\n<span class=\"kw2\">function<\/span> postToTwitter<span class=\"br0\">&#40;<\/span>event:MouseEvent<span class=\"br0\">&#41;<\/span>:<span class=\"kw3\">void<\/span><span class=\"br0\">&#123;<\/span><br \/>\ntinyLoader.<span class=\"kw3\">load<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">new<\/span> URLRequest<span class=\"br0\">&#40;<\/span><span class=\"st0\">'http:\/\/tinyurl.com\/api-create.php?url=http:\/\/nayansavla.com\/blog?p=253'<\/span> <span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n<span class=\"kw2\">var<\/span> tinyLoader:URLLoader = <span class=\"kw2\">new<\/span> URLLoader<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\ntinyLoader.<span class=\"me1\">dataFormat<\/span> = URLLoaderDataFormat.<span class=\"kw3\">TEXT<\/span>;<br \/>\n<br \/>\ntinyLoader.<span class=\"me1\">addEventListener<\/span><span class=\"br0\">&#40;<\/span>Event.<span class=\"me1\">COMPLETE<\/span>,gotTinyURL<span class=\"br0\">&#41;<\/span>;<br \/>\n<br \/>\n<span class=\"kw2\">function<\/span> gotTinyURL<span class=\"br0\">&#40;<\/span>event:Event<span class=\"br0\">&#41;<\/span>:<span class=\"kw3\">void<\/span><span class=\"br0\">&#123;<\/span><br \/>\n<span class=\"kw3\">trace<\/span><span class=\"br0\">&#40;<\/span>tinyLoader.<span class=\"kw3\">data<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"kw2\">var<\/span> reqString:<span class=\"kw3\">String<\/span> = &nbsp;<span class=\"st0\">'http:\/\/twitter.com\/home?status=Check this out '<\/span> + &nbsp;encodeURIComponent<span class=\"br0\">&#40;<\/span>tinyLoader.<span class=\"kw3\">data<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\nnavigateToURL<span class=\"br0\">&#40;<\/span><span class=\"kw2\">new<\/span> URLRequest<span class=\"br0\">&#40;<\/span>reqString<span class=\"br0\">&#41;<\/span>,<span class=\"st0\">&quot;_blank&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>&nbsp;<br \/>\nThe first thing is to get a tinyurl link and they have a api for it, the best thing is they also have a crossdomain.xml so we don&#8217;t have to worry about getting the response back within Flash.<br \/>\n&nbsp;<br \/>\nSince it returns just the url, I have set the dataFormat for my URLLoader to be text so that it gets stored in the data property and i can use it directly.<br \/>\n&nbsp;<br \/>\nNow when we get our tinyurl back its time to post it to twitter. Twitter API doesn&#8217;t mention this one possibility where you can submit any message as a post var and the main page captures it, if you are already logged in then it will populate the share screen.<br \/>\n&nbsp;<br \/>\nIts a neat little way, if you don&#8217;t want to deal with usernames and passwords on your website.<br \/>\n&nbsp;<br \/>\n<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"100\" height=\"22\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"wmode\" value=\"opaque\" \/><param name=\"src\" value=\"http:\/\/nayansavla.com\/uploads\/flash\/twitterupload\/example.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"100\" height=\"22\" src=\"http:\/\/nayansavla.com\/uploads\/flash\/twitterupload\/example.swf\" wmode=\"opaque\"><\/embed><\/object><br \/>\n&nbsp;<br \/>\nThe swf file is embedded above, if you click this button then we call tinyurl, get the link and then open a new window for twitter. If no window opens, it might be because of popup blocker. To avoid popups from Flash i have written another post, <a href=\"http:\/\/www.nayansavla.com\/blog\/?p=11\">Avoiding Popup Blockers<\/a><br \/>\n&nbsp;<br \/>\n<!-- google_ad_section_end --><br \/>\n&nbsp;<br \/>\nDownload the fla file <a href=\"http:\/\/www.nayansavla.com\/uploads\/flash\/twitterupload\/example.fla\">here<\/a>.<br \/>\n&nbsp;<br \/>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had to find a way to post a link to twitter directly from Flash. Twitter has its own API but then they expect us to collect username and password. &nbsp; If you don&#8217;t want to collect usernames and passwords on your site and still manage to post stuff to twitter directly there is a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-as-30","category-actionscript"],"_links":{"self":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=253"}],"version-history":[{"count":0,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/253\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nayansavla.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}