我正在开发一个带有spring框架的J2EE网站。我希望我的网站与推特分享,但我无法成功地使用bit.ly API。该函数提供bit.ly链接,但在Twitter的共享页面中,我只看到完整的链接。如何将bit.ly链接发送到Twitter?
我从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"})如果你尝试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&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;
}发布于 2010-09-16 13:46:35
试着改变:
for (var key in first_result) {
shortUrl = r ;
}至
shortUrl = first_result.shortUrl;如果这不起作用,请包括first_result的输出(在同一时间点)
console.log(first_result);https://stackoverflow.com/questions/3726890
复制相似问题