How to get facebook page id in iframe application (C #)

I created a simple facebook iframe application that will be used as a tab on pages. Everything works fine, but now I need to get the page ID using the tab so that I can display information related to this page.

I saw in the documentation that there is a value in signquest called "ProfileId", and that should be the id of the page I'm looking for, but every time I try to use a signed request, I run into problems so I obviously don’t understand What should I do.

Can someone explain how can I get the page id? I do not want the user to authorize the application, since I am not interested in any of their information. I just need the id of the page on which the tab appears.

+3
source share
2 answers
<?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;

?>
+3
source

You can use this information on 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
  }
}
+1
source

Source: https://habr.com/ru/post/1789236/


All Articles