Je développe un site web J2EE avec un framework Spring. Je souhaite que mon site Web soit partagé avec Twitter, mais je n'ai pas réussi à utiliser l'API bit.ly. la fonction fait un lien bit.ly mais dans la page de partage de Twitter, je ne vois que le lien complet. Comment puis-je envoyer le lien bit.ly à Twitter?Comment utiliser bit.ly pour Twitter
La réponse bit.ly que je reçois de 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"})
Si vous essayez http://twitter.com/home?status=http://www.google.com vous pouvez me comprendre.
Mon code est ci-dessous:
<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;
}
Je ne peux pas utiliser console.log parce que je le site Web est dans un fichier XML mais j'ai utilisé javascript et il a créé le lien court mais le problème est toujours le même. Il crée un raccourci pour tweeter le lien original. Sortie: http: //bit.ly/bMMjUh pour l'alerte (first_result); – yyy