views:

71

answers:

1

Hi,

I'm developing a J2EE website with spring framework. I want my website to share with Twitter but I couldn't succeed using bit.ly API. the function makes bit.ly link but in Twitter's share page I only see the full link. How can I send the bit.ly link to Twitter?

The bit.ly response which I get from firebug:

BitlyCB.getBitlyUrl({"errorCode": 0, "errorMessage": "", "results": {"http://twitter.com/home?status=http://www.google.com": {"userHash": "dodUFu", "hash": "9KnUl2", "shortUrl": "http://bit.ly/dodUFu", "shortCNAMEUrl": "http://bit.ly/dodUFu", "shortKeywordUrl": ""}}, "statusCode": "OK"})

If you try http://bit.ly/dodUFu you can understand me.

My code is below:

<script type="text/javascript" charset="utf-8"
    src="http://bit.ly/javascript-api.js?version=latest&amp;amp;login=mylogin&amp;amp;apiKey=mykey"&gt;&lt;/script&gt;
<a class="_ffShare_"
onclick="onlyShortenUrl('http://twitter.com/home?status=http://mypage');"&gt;
<img src="http://yakup-laptop:8080/images/theme/default/twitter.png"&gt;&lt;/img&gt;
</a>

    function onlyShortenUrl(longUrl){
    //single shortener
    BitlyCB.getBitlyUrl = function(data) {
        var shortUrl = extractShortUrl(data);
        window.open(shortUrl,'_blank');
        return shortUrl;
    }
    return BitlyClient.call('shorten', {'longUrl': longUrl}, 'BitlyCB.getBitlyUrl');
    }

    function extractShortUrl(data){    
    //bitly util method probably not useful standalone
       var shortUrl = '';
       var first_result; 
       // Results are keyed by longUrl, so we need to grab the first one.
       for (var r in data.results) {
         first_result = data.results[r]; break;
       }
       for (var key in first_result) {
         shortUrl = r ;
       } 
       return shortUrl;
   }
A: 

Try changing:

for (var key in first_result) {
         shortUrl = r ;
}

to

shortUrl = first_result.shortUrl;

If that doesn't work, please include the output (at that same point) of first_result:

console.log(first_result);
michael
I can't use console.log beacause I the web site is in a XML file but I used javascript and it created the shortlink but the problem is still the same. It creates a shortcut to Tweet the orginal link. Output:http://bit.ly/bMMjUh for alert(first_result);
yakup