페이스북
요청 URL:
http://graph.facebook.com/?id=[URL]&callback=[콜백 함수 이름]
반환값(JS형식):
[콜백 함수 이름]({
"id":"[URL]",
"shares":"[공유수]", /*0일 경우 반환값에 기재 안 됨*/
"comments":"[댓글수]" /*0일 경우 반환값에 기재 안 됨*/
});
트위터
요청 URL:
http://urls.api.twitter.com/1/urls/count.json?url=[URL]&callback=[콜백 함수 이름]
반환값(JS형식):
[콜백 함수 이름]({
"count":"[공유수]", /*0일 경우에도 반환값에 기재됨*/
"url":"[URL]"
});
Google+
구글 플러스는 아직까지 URL이나 서버로 공유수를 불러오는 기능을 제공하지 않는 것으로 보임.
미투데이
미투데이는 아직 공유수에 대해 OEPN API를 지원하지 않음.
카카오스토리
카카오스토리 역시 아직 공유수를 지원하지 않음.
사용 예시
<script>
(function(){
var s=document.createElement('script');
s.src="http://graph.facebook.com/?id="+[URL]+"&callback=parse_fb";
document.body.appendChild(s);
s=document.createElement('script');
s.src="http://urls.api.twitter.com/1/urls/count.json?url="+[URL]+"&callback=parse_tw";
document.body.appendChild(s);
})();
function parse_fb(d){
if(typeof d.shares!="undefined"){
$('[SELECTOR]').html(d.shares);
}else{
$('[SELECTOR]').html(0);
}
}
function parse_tw(d){
$('[SELECTOR]').html(d.count);
}
</script>
페이스북 댓글