Jul 09 2009

Posting to Twitter from Flash using Tiny Url

Published by at 7:44 am under AS 3.0,Flash

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.
 
If you don’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.
 
It turned out to be really easy and here is how,
 

import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;

shareBlog.addEventListener(MouseEvent.CLICK,postToTwitter);

function postToTwitter(event:MouseEvent):void{
tinyLoader.load(new URLRequest('http://tinyurl.com/api-create.php?url=http://nayansavla.com/blog?p=253' ));
}

var tinyLoader:URLLoader = new URLLoader();
tinyLoader.dataFormat = URLLoaderDataFormat.TEXT;

tinyLoader.addEventListener(Event.COMPLETE,gotTinyURL);

function gotTinyURL(event:Event):void{
trace(tinyLoader.data);
var reqString:String =  'http://twitter.com/home?status=Check this out ' +  encodeURIComponent(tinyLoader.data);
navigateToURL(new URLRequest(reqString),"_blank");
}

 
The 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’t have to worry about getting the response back within Flash.
 
Since 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.
 
Now when we get our tinyurl back its time to post it to twitter. Twitter API doesn’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.
 
Its a neat little way, if you don’t want to deal with usernames and passwords on your website.
 

 
The 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, Avoiding Popup Blockers
 

 
Download the fla file here.
 

22 responses so far

22 Responses to “Posting to Twitter from Flash using Tiny Url”

  1. Glennon 01 Aug 2010 at 11:19 am

    exactly what i was looking for!

    but the link to the download is:

    http://http//nayansavla.com/uploads/flash/twitterupload/example.fla

    so people cant download it :(

  2. Nayanon 01 Aug 2010 at 6:09 pm

    Hi Glenn,

    thank you for pointing it out to me. its fixed now.

    Nayan

  3. Nanyon 09 Sep 2010 at 1:00 pm

    Hi!
    I´m Nany, flash developer from Netestudio, a Brazillian internet agency. And I want to tank you so much for you help!
    I hope I could help you some day…
    Thanks!

  4. Nayanon 09 Sep 2010 at 11:17 pm

    Hi Nany,

    I am glad this post was useful to you.

    Regards,
    Nayan

  5. pete shandon 24 May 2011 at 3:16 am

    The reason your having problems with popup blockers is because you’re calling navigateToURL from a function that isn’t a MouseEvent. An easier way to avoid popup blockers would be to simply perform the get tiny url prior to user interaction, store the new url in a variable and then use the new url when the user clicks the button.

  6. chianon 29 Dec 2011 at 9:29 pm

    thank you for sharing.
    however its doesn’t work with “&” character in the url. any idea ?

    regards
    Chian

  7. jam Tangan Fossilon 11 Dec 2015 at 10:14 am

    Helpful info. Fortunate me I discovered your web site by chance, and I am surprised why this accident did not came about earlier!

    I bookmarked it.

  8. خرید مقالهon 21 Jun 2016 at 4:28 am

    I know this web site provides quality dependent content and extra material,
    is there any other web page which provides these kinds of things
    in quality?

  9. Folti Bafiion 11 Aug 2016 at 11:36 pm

    Wow, superb weblog format! How lengthy have you been running a blog
    for? you made blogging look easy. The entire glance
    of your site is wonderful, as well as the content material!

  10. proxy scraping linkson 30 Aug 2017 at 7:27 pm

    What i do not understood is in reality how you’re not really much more smartly-appreciated than you
    may be now. You are very intelligent. You recognize thus
    significantly in terms of this topic, made me individually consider it from numerous various angles.
    Its like women and men are not fascinated except it
    is one thing to accomplish with Woman gaga! Your own stuffs great.
    All the time care for it up!

  11. Engineering and Energy Logoson 04 Sep 2017 at 8:32 pm

    There are some interesting time limits on this article however I don’t know if I see all of them heart to heart. There’s some validity however I’ll take maintain opinion until I look into it further. Good article , thanks and we want more! Added to FeedBurner as properly

  12. Merrillon 16 Dec 2017 at 9:21 am

    This aгticle will asѕist the internet visitors fooг creating new web site or even a bloɡ from stɑrt to еnd.

  13. Pozycjonowanie UKon 16 Sep 2018 at 10:31 pm

    Ӏ’m trᥙly enjoyingg the design аnd layout
    of your blog. It’s a very easy օn the eyes which makes it
    mucch more enjoʏable for me to come her and visit more often. Dіd yoս hіre out a developer to creatе your theme?
    Outstanding worҝ!

  14. togel hongkongon 27 Jan 2019 at 4:49 am

    Can I just say what a relief to uncover someone who really knows what they are talking about on the web.
    You actually know how to bring a problem to light and make
    it important. More people really need to check this out
    and understand this side of the story. I can’t
    believe you’re not more popular given that you surely have the gift.

  15. Abcya Unblockedon 03 Feb 2019 at 4:37 am

    Having read this I thought it was really informative. I appreciate you spending some time and effort to put this
    article together. I once again find myself personally spending a lot
    of time both reading and posting comments. But so what,
    it was still worth it!

  16. Abcya Mathon 25 Feb 2019 at 10:16 am

    Hi there, You’ve done a fantastic job. I’ll definitely digg it and
    personally recommend to my friends. I’m sure they will be benefited from
    this web site.

  17. suhutogelon 22 May 2020 at 1:02 pm

    My brother recommended I might like this website.
    He used to be totally right. This publish truly made my day.
    You can not consider simply how much time I had spent
    for this info! Thanks!

  18. Marylinon 05 Dec 2020 at 1:46 am
  19. daftar bso118on 17 Apr 2021 at 10:29 pm
  20. wordpresson 20 Sep 2022 at 11:33 pm

    Avoid boat neck, broad scoop necklines and brief sleeves, as these
    emphasize broadness with horizontal traces.

  21. A traditional night gown with the proper neckline, colors, and sleeve size will add to
    your ultimate outfit.

Trackback URI | Comments RSS

Leave a Reply