How to get the facebook page id in an iframe app (C#)
I've created a simple facebook iframe app to be used as a tab on pages. It all works fine but I now need to get the id of the page that using the tab so I can display information particular to that page.
I've seen in the documentation that there's a value called "ProfileId" in the signedrequest and that should be the id of the page which is what I'm looking for but everytime I try to use the signedrequest I run into problems so I obviously don't understand what I need to do.
Can some开发者_如何学运维one explain how I can get the page id? I don't want the user to have to authorize the app as I'm not interested in any of their information I just want the id of the page that the tab is appearing on.
<?php
include "facebook.php"; //Facebook PHP SDK
$app_id = "APP_ID_HERE"; // Your application id
$app_secret = "APP_SECRET_HERE"; // Your application secret
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signedrequest = $facebook->getSignedRequest();
$page_id = $signedrequest["page"]["id"];
$is_admin = $signedrequest["page"]["admin"];
$is_liked = $signedrequest["page"]["liked"];
echo "Page id: ". $page_id;
?>
You can use the information in FacebookWebContext.Current.SignedRequest.Data:
if (FacebookWebContext.Current.SignedRequest != null)
{
dynamic data = FacebookWebContext.Current.SignedRequest.Data;
if (data.page != null)
{
var pageId = (String)data.page.id;
var isUserAdmin = (Boolean)data.page.admin;
var userLikesPage = (Boolean)data.page.liked;
}
else
{
// not on a page
}
}
精彩评论