2014-04-11 4 views
0

나는 어디에서 쳐다볼 지 알 수 없기 때문에 몇 가지 초기 방향을 지정하는 제 사이트에 대한 아이디어를 가졌습니다.웹 사이트 사용자가 페이스 북 페이지를 공유하고 포인트를 할당 할 때를 추적하십시오

사용자가 페이스 북에서 사이트를 공유하고 각 공유에 대해 점수를 집계 할 수있는 가입 기반 사이트를 개발 중입니다. 특정 포인트에 도달하면 구독 할인을 받게됩니다.

사이트는 워드 프레스 다중 사이트이므로 사용자는 가입 한 주요 사이트에 자신의 계정 영역을 가지고 있습니다. 여기에는 점수 계산 기록 (즉, Wordpress 관리 대시 보드가 아닌)이 있습니다.

사용자가 페이지를 공유 할 때 어떻게 추적하는지, 그리고 매번 포인트를 할당하는 방법에 대해 올바른 방향으로 나를 가리켜 주실 수 있습니까?

+0

전에 페이스 북을 통합 했습니까? 페이스 북의 그래프 API로 작업 했습니까? –

+0

약간의 예,하지만 배우기를 원합니다 - 어디서부터 시작 해야할지 확실하지 않습니다 –

+0

꽤 많은 질문이 될 것입니다. 어쨌든 아픈 당신을 설명하려고합니다. 자바 스크립트가 작동합니까? 또한 DB 권한에 포인트를 저장하고 싶습니까? –

답변

1

사용자 식별자 (예 : 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> 

질문이 광범위했기 때문에 여기에 코드를 붙여 넣었습니다. 이 점에 어려움이 있으면 알려주십시오.

+0

@Sahil Mittal에게 감사드립니다. 이것은 나에게 좋은 출발점입니다. 내가 어떻게 일어나는지, 내가 설명이 필요한지 알려주지. –