페이스북, 트위터 콜백
페이스북
// 페이스북 스크립트
window.fbAsyncInit = function(){
//페이스북 앱 아이디 생성
FB.init({
appId : 'your app id',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true
});
FB.ui({
method: 'feed',
name: caption,
description: description,
//caption: '',
link: document.location.href,
picture: picture,
user_message_prompt: ''
}, function(response){ // 공유 결과 리턴
if(response === null || response == undefined) { // 공유 안함
}else{ // 공유 함
alert('페북 공유 완료');
}
});
});
};
// 페이스북 스크립트
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.async = true;
js.src = "//connect.facebook.net/ko_KR/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
트위터
// 트위터 스크립트
$.getScript("http://platform.twitter.com/widgets.js", function(){
function handleTweetEvent(event){ // 트윗했을 시 호출되는 함수
if (event) {
alert('트윗 완료');
}
}
twttr.events.bind('tweet', handleTweetEvent); // 트윗했을 시 이벤트 바인딩
});
-> 트위터 버튼
<a href="" id="tweet" data-count="horizontal" data-url="" target="_blank">
<img src="/images/user/promotion/btn_twitter.png" style="display:none;" alt="트위터 공유" />
</a>
<script>
var link = document.location.href
var url = "https://twitter.com/intent/tweet?original_referer="+encodeURIComponent(link)+"&text=" + encodeURIComponent(description) + encodeURIComponent(link);
$("#tweet").attr("href", url);
$("#tweet").attr("data-url", document.location.href);
$("#tweet")[0].click(); // 트윗 창 오픈
</script>