사용자 식별자 (예 : user_id)가 필요한 경우 그래프 API를 사용해야하며 사용자는 먼저 자신을 대신하여 게시를 허용하기 위해 앱을 인증해야합니다.
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{app-id}',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
share(response.authResponse.userID);
} else if (response.status === 'not_authorized') {
login();
} else {
login();
}
});
};
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function login()
{
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
share(response.id);
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
},{scope: "publish_stream"});
}
function share(id)
{
FB.api(
"/me/feed",
"POST",
{
"object": {
"message": "This is a test message",
"link": "{your-website-link}"
}
},
function (response) {
if (response && !response.error) {
//make an ajax call and save the update the points wrt userId
}
}
);
}
</script>
<div id="fb-root"></div>
코드 자체는 자명하다.
참고 : FB.login
, FB.getLoginStatus
, 이미 사용자 식별자가있는 경우, 대신 당신이이없이 할 수 공유 할 Feed Dialog를 사용하여, 그래프 API를 사용할 필요가없는 /me/feed
사용자가 앱을 인증합니다.
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{app-id}',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.ui({
method: 'feed',
link: "{your-website-link}"
}, function(response){
// share successful
//ajax call here to save points
});
};
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<div id="fb-root"></div>
질문이 광범위했기 때문에 여기에 코드를 붙여 넣었습니다. 이 점에 어려움이 있으면 알려주십시오.
전에 페이스 북을 통합 했습니까? 페이스 북의 그래프 API로 작업 했습니까? –
약간의 예,하지만 배우기를 원합니다 - 어디서부터 시작 해야할지 확실하지 않습니다 –
꽤 많은 질문이 될 것입니다. 어쨌든 아픈 당신을 설명하려고합니다. 자바 스크립트가 작동합니까? 또한 DB 권한에 포인트를 저장하고 싶습니까? –