How to get facebook page id inside fan tab page using facebook javascript sdk

I am trying to create a web application creating fan tabs for facebook pages ...

my problem...

I tried this: -

FB.api(
"/{page-id}/feed",
function (response) {
  if (response && !response.error) {
    /* handle the result */
  }
}

);

How to get facebook page id inside page fan tab using facebook javascript sdk?

this is an image describing what i want to do: http://www.wtttc.com/image.php?id=25

I tried everything but not used :(

Thank you

+3
source share
5 answers

, signed_request Facebook. https://developers.facebook.com/docs/facebook-login/using-login-with-games#checklogin , , .

, , ,

HTTP POST URL-, Canvas URL- .

, , HTTP POST. , javascript. Javascript - , POST. , javascript- .jsp/.php/... . javascript. JSP:

<%String signedRequest = request.getParameter("signed_request");%><script>window.signedRequest = "<%=signedRequest%>"</script>

javascript , , .

var signedRequest = global.signedRequest;
        var data1 = signedRequest.split('.')[1];
        data1 = JSON.parse(base64decode(data1));
        console.log(data1);

:

Object {algorithm: "HMAC-SHA256", expires: 1404925200, issued_at: 1404921078, oauth_token: "CAAUT5x1Ujq8BAPzh2ze1b4QTBkcZAtRCW6zA1xJszUasqoEPp…Fy8fAVEZAyhVaxEaq6ZBw6F4bSFI1s8xtXbBLp7oBFL4wZDZD", page: Object…}

: "HMAC-SHA256" : 1404925200 : 1404921078 oauth_token: "CAAUT5x1Ujq8BAPzh2ze1b4QTBkcZAtRCW6zA1xJszUasqoEPpFRfM1ln3x9pb7mLBujyug5iHUifSnyxmPHOLe030wI3H5DYXubnxbPhww9aipSnwoEr6lwctuQaGKxYvDBdZCNuFiaYIduORTWirmZC2rKL86Fy8fAVEZAyhVaxEaq6ZBw6F4bSFI1s8xtXbBLp7oBFL4wZDZD" : : user_id: "1519950734891144" :

.

Object {id: "1522695611287219", liked: true, admin: true} 

, , https://developers.facebook.com/docs/facebook-login/using-login-with-games#checklogin .

, .

+1

fql, , .
https://developers.facebook.com/docs/reference/fql/
, :

var currentPageID;
var url = window.top.location;
FB.api(
    {
        method: 'fql.query',
        query: "SELECT id FROM object_url WHERE url = '" + url + "'"
    },
    function(response) {
        currentPageID = response[0].id;
    }
);
alert(currentPageID);
0

http://www.wtttc.com/image.php?id=25

window.top.location;

facebook... ...

:)

0

, SDK Javascript Facebook parseSignedRequest.

. , PHP, , .

html- ( , ):

<head>
.....
<script type="text/javascript">
    // set a variable with the signed_request sent to your app URL by Facebook via POST
    var signedRequest = "<?php echo $_REQUEST["signed_request"] ?>";

    FB.getLoginStatus(function (response) {
        // do not use the response.authResponse.signedRequest but the one above instead
        // and let the javascript SDK parse the good signed_request for you
        var page = this.parseSignedRequest(signedRequest).page;
        // is the current user an admin of this page? true/false
        var isAdmin = page.admin;
        // do you like this page? true/false
        var isLiked = page.liked;
        // and here is the Facebook page ID
        var pageID = page.id;
        if (response.status === 'connected') {
            // user is connected

        } else if (response.status === 'not_authorized') {
            // the user is logged in to Facebook,
            // but has not authenticated your app

        } else {
            // the user isn't logged in to Facebook.

        }

    }, true);
<script>

, . .

0

You should get signed_request POSTed for your application from the server side. https://developers.facebook.com/docs/pages/tabs Follow the link to get an idea of ​​the page tab and page id.

0
source

All Articles