bringing your vision to life

Retrieve Facebook fan page id, Facebook app page id php

So This helpful entry hopefully helps some one trying to dynamically retrieve some facebook id for the the fan page the user is currently looking at.

I searched the Facebook documentation and referred consistently to this but didn't straight explain how to get this dynamic variable in php.

So it's quite simple really once you find it but you can see it here:  This will allow you to retrieve the current page's id... no need to curl it and parse the id, it's right here.

<?php

print $_REQUEST['fb_sig_page_id'];

?>

 

We used this is the implementation and delivery of the juno wallet facebook fanpage application which can be seen here:

http://www.facebook.com/pages/Apollo-Matrix-LLC/120845234620618?v=app_13...

 

hope this helps, and as always apollo matrix can help with all of your face book apps...

Facebook get current URL, Current Facebook page, get current facebook url

While building a facebook applicaiton that will be utilized across 100's of pages it was found a slight challenge to grab the current url dynamically...

First try:

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
 
$currenturl = curPageURL();

A simple curl call was tried, however the server where the .php was was called not the facebook url

 

What worked:

<?php

$pageid = $_REQUEST['fb_sig_page_id'];

//grabs the current page id then use the current page id with the graph api

$jsonurl = file_get_contents("https://graph.facebook.com/" . $pageid);
$urlobj = json_decode($jsonurl);
$curUrl = $urlobj->{'link'};

print $curUrl;

?>

Hope this helps for anyone