BGM용 세이라디오
열기▼       고정
전체
글목록

페이스북, 트위터의 URL 공유수 불러오기(JS 필요)

일요일, 11월 17, 2013

(JSON 데이터를 이용해 JS코드로 작업한다. 로그인이나 인증 과정도 필요없다.)

페이스북

요청 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>
첫 댓글을 써주세요!

댓글을 인용하려면 @![댓글 ID]!@와 같이 쓰시면 됩니다. "@!" 와 "!@"를 쓰시려면 "+@+!+", "+!+@+"와 같이 써주세요.

페이스북 댓글
.post-outer{ -webkit-transform:none; transform:none; display:inline; padding:0; margin:0; border-width:0; } .hentry>div{ display:none; }