Finding page id of Facebook fan-page
Sometimes you come to a situation when you need the page id of the Facebook fan page. This happens usually when you are writing Facebook application that needs to use the Facebook fan-pages. If you have been to the situation then here's you solution. It just a few lines of code
which is as follows:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* A simple library to assist in getting the Facebook Fan Page Id | |
* @author Paras Nath Chaudhary | |
* @copyright CopyLeft (ↄ) 2013, writephp.blogspot.com | |
* @license GPL | |
* @since Version 1.0 | |
* @version 1.0 | |
Implementation | |
================ | |
<?php | |
require_once 'facebookHelper.php'; | |
echo getPageId("http://www.facebook.com/nosklub"); | |
?> | |
*/ | |
function getPageId($fanpageUrl){ | |
$url=str_replace('www', 'graph', $fanpageUrl); | |
$json = file_get_contents($url); | |
$contents=json_decode($json); | |
return $contents->id; | |
} | |
?> |
No rocket science right? :) And yeah one more thing to add, this not only just gives you the id of your fanpage, it also returns the facebook id of the user, supplied the persons facebook url e.g. http://www.facebook.com/opnchaudhary
Comments
Post a Comment