Well I am new to FaceBook Graph API or FaceBook API in general but that doesn’t stop me to share if I come up with something useful.
Why do you need to know your FaceBook ID?
I am a WordPress developer too and there are many social plugins that need to know your FaceBook ID. But that’s not the only reason, another reason is exactly why you are reading this.
Anyway lets jump on How To
First Download the latest PHP SDK from GitHub. Here is the URL https://github.com/facebook/facebook-php-sdk
Extract the archive to your current working directory or to somewhere where you place your external libraries.
The Code Example
// instantiate facebook object with your app ID and secret
$facebook = new Facebook(array(
'appId'=>"155793788888888", // <-- use your own AppId here
"secret"=>"4r0d000567a284a129319837912873912" // <-- use application secret provided by FaceBook
// get the logged in user if any
$user = $facebook->getUser();
// this is suppose to work every time as long as the username is correct else it will throw a Fatal error
$user = $facebook->api('/jaspreetsingdhchahal');
[id] => 1049409782
[name] => Jaspreet Chahal
[first_name] => Jaspreet
[last_name] => Chahal
[username] => jaspreetsinghchahal
[gender] => male
[locale] => en_US
So as you can see that it is dead simple and I can get my ID from above array as $user[“id”]
This post actually shows how to use/create a FaceBook Object using your appId and secret
If you haven’t created your FaceBook Application yet, here is a link to create one
I hope this helps