Is there a way to get the name of a Facebook page using PHP?

I am creating an iframe application that will have a few mentions of a Facebook page. My application will be added to several pages with different names. I need something like this.

$page_name = "Bob Toys"; Thank you for visiting the <?php echo $page_name; ?> page! 

Is there any way to do this?

+6
source share
4 answers

Yes there is. Decode signed_request sent to your Facebook page.

 if (!empty($_REQUEST['signed_request'])) { $signedRequest = $_REQUEST['signed_request']; list($sig, $payload) = explode('.', $signedRequest, 2); $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); } 

From this you can get the page id.

 array (size=4) 'algorithm' => string 'HMAC-SHA256' (length=11) 'issued_at' => int 1321635439 'page' => array (size=3) 'id' => string '19292868552' (length=15) 'liked' => boolean false 'admin' => boolean true 'user' => array (size=3) 'country' => string 'gb' (length=2) 'locale' => string 'en_US' (length=5) 'age' => array (size=1) 'min' => int 21 

Then you can use the Graph API to return the page object, which will look like this: https://graph.facebook.com/19292868552

+5
source

Just enter the page ID, request a graph with only the name field. sort of:

 <?php $signed_request = $_REQUEST["signed_request"]; list($encoded_sig, $payload) = explode('.', $signed_request, 2); $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); if (!empty($data["page"])) { $page_info = json_decode(file_get_contents("https://graph.facebook.com/{$data['page']['id']}?fields=name")); echo $page_info->name; } ?> 
+1
source

You can try the following:

 $page_profile = $facebook->api('/' . $pageid); echo "<a href='" . $page_profile['link'] . "'>" . $page_profile['link'] . "</a>"; 
0
source

it worked for me

$ page_profile = $ facebook-> api ('/'. $ pageid);

$ page_name = $ page_profile ['name'];

0
source

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