티스토리 뷰

참조 : https://developers.facebook.com/docs/guides/appcenter/#authorization
참조 : https://developers.facebook.com/docs/reference/login/
참조 : https://developers.facebook.com/docs/reference/javascript/FB.api/



window.fbAsyncInit = function() {                                                                                                                                     
	FB.init({                                                                                                                                                           
		appId      : 'app_id', // App ID    
		status     : true, // check login status
		cookie     : true // enable cookies to allow the server to access the session 
	});                                                                                                                                                                 

	// Check if the current user is logged in                                                                                                                           
	// and has authorized the app          

	FB.login(function(response) {
		if(response && response.status == 'connected') {   
			FB.api('/me', function(response) {
				var message = document.getElementById('welcomeMessage');
				message.innerHTML = '안녕하세요? ' + response.last_name + response.first_name + "님!";
			});  
		} else {
		}    
	}, {scope: 'publish_stream,offline_access,read_stream'});
};

// Load the SDK Asynchronously
(function(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) return;
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/ko_KR/all.js#xfbml=1&appId=#appID";
	fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function FBWrite() {
	var u_message = "메세지";
	var u_picture = "이미지 절대경로 혹은 상대경로";
	var u_link = "링크 주소";
	var u_source = "비디오 경로";

	FB.api('/me/feed','post',{ message: u_message + new Date().getTime(), picture: u_picture, source: u_source, link: u_link }, function (response) {
		if (!response || response.error) {
			alert('Error occured');
		} else {
			alert('POSTID:' + response.id);
		}
	)};
}

// div id="welcomeMessage" 필요
// input value="FB Write" onclick="FBWrite()" type="button" 필요

'SNS > FACEBOOK' 카테고리의 다른 글

페이스북 (펜페이지 OR APP 페이지) 좋아요 여부 체크  (1) 2012.03.20
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함