Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2005
    Posts
    4,486
    Tokens
    921

    Latest Awards:

    Default Shorten URL using bit.ly (Javascript)

    Hello there. For my forum I wish to use Javascript to shortern the page url into a bit.ly URL and then for the bit.ly URL to be put into a Javascript var ready to be called in my twitter re-tweet script.

    You can find my current twitter re-tweet script below. At the moment it can get the page URL and title and then tweet these. What I want it the page URL to be first shortened using bit.ly (js) and then the new short-url echoed instead of twtUrl.
    Code:
              // Variables for twitter to use
              var twtTitle  = document.title;
              var twtUrl    = location.href;
              var maxLength = 140 - (twtUrl.length + 1);
              if (twtTitle.length > maxLength) {
              twtTitle = twtTitle.substr(0, (maxLength - 3))+'...';
              }
              var twtLink = 'http://twitter.com/home?status='+encodeURIComponent(twtTitle + ' ' + twtUrl);
              document.write('<a href="'+twtLink+'" target="_blank"'+'>Tweet This!<'+'/a>');
    I hope you understand what I mean. Kind regards.
    "RETIRED" FROM HABBO(X)

    :¬:

    TOMSPIT / COWLY05


  2. #2
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default

    Probs not right, but could any of this be any use?

    http://code.google.com/p/bitly-api/w...iDocumentation

  3. #3
    Join Date
    Nov 2005
    Posts
    4,486
    Tokens
    921

    Latest Awards:

    Default

    @LukeBateson: I've attempted to use the API demos, but as I have very limited JS knowledge, I am not able to turn the demo; http://bit.ly/app/demos/shorten.html

    Into somthing that will output a var for me to use in my twitter script.
    "RETIRED" FROM HABBO(X)

    :¬:

    TOMSPIT / COWLY05


  4. #4
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default

    Quote Originally Posted by TomSpit View Post
    @LukeBateson: I've attempted to use the API demos, but as I have very limited JS knowledge, I am not able to turn the demo; http://bit.ly/app/demos/shorten.html

    Into somthing that will output a var for me to use in my twitter script.
    Well, I'm not really a Javascript guru myself, so can't help lol.
    Sorry

    Luke

    Rep returned
    Last edited by Luke; 09-01-2010 at 01:39 PM.

  5. #5
    Join Date
    Nov 2005
    Posts
    4,486
    Tokens
    921

    Latest Awards:

    Default

    Thanks and no problem. Anyone else? Should be a simple job, I would think.
    "RETIRED" FROM HABBO(X)

    :¬:

    TOMSPIT / COWLY05


  6. #6
    Join Date
    Nov 2005
    Posts
    4,486
    Tokens
    921

    Latest Awards:

    Default

    Bump, will offer +REP for help!
    "RETIRED" FROM HABBO(X)

    :¬:

    TOMSPIT / COWLY05


  7. #7
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Try something like this (you'll need to change the Bit.ly API key, etc):
    HTML Code:
    <script type="text/javascript" charset="utf-8" src="http://bit.ly/javascript-api.js?version=latest&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07"></script> 
    <script type="text/javascript">
    	<!--
    	
    		document.write( '<div id="tweet-this"></div>' );
    				
    		BitlyClient.addPageLoadEvent(function(){
    	
    			BitlyCB.myShortenCallback = function( data ) {
    
    				var result;
    				
    				for( var r in data.results ) {
    				
    					result                    = data.results[ r ];
    					result[ 'longUrl' ]    = r;
    					
    					break;
    					
    				}
    				
    				var twtTitle  = document.title;
    				var twtUrl    = result[ 'shortUrl' ];
    				var maxLength = 140 - ( twtUrl.length + 1 );
    			
    				if( twtTitle.length > maxLength ) {
    				
    					twtTitle = twtTitle.substr( 0, ( maxLength - 3 ) ) + '...';
    				
    				}
    				
    				var twtLink = 'http://twitter.com/home?status=' + encodeURIComponent( twtTitle + ' ' + twtUrl );
    				
    				document.getElementById( 'tweet-this' ).innerHTML = '<a href="' + twtLink + '" target="_blank">Tweet This!</a>';
    				
    			}
    			
    			BitlyClient.shorten( document.location, 'BitlyCB.myShortenCallback' );
    	
    		});
    
    	-->
    </script>
    Last edited by Invent; 09-01-2010 at 06:29 PM.

  8. #8
    Join Date
    Nov 2005
    Posts
    4,486
    Tokens
    921

    Latest Awards:

    Default

    Worked brilliantly. Thank you. Now time to customize it
    "RETIRED" FROM HABBO(X)

    :¬:

    TOMSPIT / COWLY05


  9. #9
    Join Date
    Jan 2011
    Posts
    1
    Tokens
    0

    Default

    Great script! Works perfect for me too! Is it possible for this tweeter custom button to also include a twitter username (just like the official button does ex: via @johndoe) that we specify? 10x in advance!
    Last edited by Sorin; 11-01-2011 at 12:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •