如何将 bit.ly 用于 Twitter

发布于 2024-09-19 21:34:31 字数 1828 浏览 9 评论 0 原文

我正在使用 spring 框架开发一个 J2EE 网站。 我希望与 Twitter 分享我的网站,但使用 bit.ly API 无法成功。该函数生成 bit.ly 链接,但在 Twitter 的共享页面中我只看到完整链接。 如何将 bit.ly 链接发送到 Twitter?

我从 firebug 得到的 bit.ly 回复:

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"})

如果您尝试 http://twitter.com/home?status=http://www.google.com 你可以理解我。

我的代码如下:

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

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://twitter.com/home?status=http://www.google.com you can understand me.

My code is below:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-09-26 21:34:31

尝试将:更改

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

shortUrl = first_result.shortUrl;

如果这不起作用,请包含 first_result 的输出(在同一点):

console.log(first_result);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文