gpt4 book ai didi

javascript - 如何将 bit.ly 用于 Twitter

转载 作者:行者123 更新时间:2023-11-28 10:28:22 25 4
gpt4 key购买 nike

我正在使用 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;
}

最佳答案

尝试改变:

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

shortUrl = first_result.shortUrl;

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

console.log(first_result);

关于javascript - 如何将 bit.ly 用于 Twitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3726890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com