Bid.lyで短縮URL

今さらですが、短縮URLをjsonpで取ってみました。

ApiDocumentation – bitly-api – bit.ly REST API method documentation – Project Hosting on Google Code.

http://bit.ly

でアカウントを作成してください。

ログインして以下のURLから

http://bit.ly/a/account

login
apiKey
を確認してご自身の情報を入れてください。

shortenで短縮します。scriptはこんな感じで。

<script type=”text/javascript”>
var Bitly = {
login: ‘ここにログインID’,
apiKey: ‘ここにAPIキーを’,
format: ‘json’,
shortenUrl: “http://api.bit.ly/v3/shorten”,
getUrl: function(){

}
shorten: function(longUrl) {
$.ajax({
type: “GET”,
url: Bitly.shortenUrl,
data: {
login: Bitly.login,
apiKey: Bitly.apiKey,
format: Bitly.format,
longUrl: longUrl
},
dataType: “jsonp”,
success: function(data, dataType) {
return Bitly.shortenCallback(data);
}
},
shortenCallback: function(data){
console.log(data.data.url);
}
};
</script>

でスクリプト内で
Bitly.shorten(‘http://blog.bbtune.com/’);
とするとfirebugやchromeでみるとconsoleにurlがでます。

This entry was posted on 土曜日, 7月 10th, 2010 at 2:45 PM and is filed under bitly, Social. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。