bit.lyでURLを短縮化してからtweetするブックマークレットを作る
高速コーディングが可能なVim+Zen-Codingのメモ http://d.hatena.ne.jp/nzm_o/20100605/1275747401
ではなく、
高速コーディングが可能なVim+Zen-Codingのメモ http://bit.ly/xxxxx
とURLを短縮化しつつtweetするようなブックマークレットを作る方法。
▼作成方法
APIを利用するため、まずbit.lyでアカウントを作成
http://bit.ly/a/sign_in
アカウントを作成すると、API Keyが発行されるので、これをメモっておく。
例)アカウントID : hogehoge
例)API Key: R_6819xxxxxxxxxxxxxxxxxxxxxxx3bc4
以下のAPIを呼ぶと短縮化されたURL(赤字部分)がレスポンスされる
レスポンス(json)
callback({ "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/yahoo.co.jp\/;", "url": "http:\/\/bit.ly\/dafBEu", "hash": "dafBEu", "global_hash": "92Bolp", "new_hash": 0 } })
上記を踏まえ次のようなスクリプトを改行なしでブックマークに登録すれば完成。
javascript: var i='(アカウントID)'; var k='(API Key)'; var d=document; var h=location.href; var u='http://api.bit.ly/v3/shorten?format=json&callback=callback&login='+i+'&apiKey='+k+'&longUrl='+encodeURIComponent(h); st=d.createElement('script'); st.type='text/javascript'; st.src=u; d.body.appendChild(st); function callback(r){ t=d.title; location.href='http://twitter.com/home?status='+encodeURIComponent(t+' '+r.data.url); }
※上記のjavascriptのアカウントIDとAPI Keyを書き換えてお使いください。
できる100ワザ ツイッター Twitterパーフェクトテクニック (できる100ワザシリーズ)
posted with amazlet at 10.07.16
おすすめ度の平均:
基本は全て学べますので、超おすすめ!