PHP API TutorialsPHP TutorialsWeb Development

How to find facebook id or url is a page or profile using Graph API without access token

In this tutorial, I will teach you “How to find facebook id or url is a page or profile using Graph API without access token”. In the previous version of Facebook API  results will be as  : –

Above url will result in JSON format as shown below : –

But it does not show id is related with page or profile.

Find Facebook  id or Url belongs to Page or Profile Using Graph API

In above graph API example code now needs a access token . In above code 100008426462579 is a profile id. However if you replace this id with page id then result will be same only name and id will be changed. If you want to know facebook id belongs to page or profile or even getting default results. You need to add token in graph API url as shown below :-<!--Your Token-->

Facebook access token grants permission to know the result of that id. However, access token has a time limit for maximum two months. After two months you have to re-generate this token. If you are building application in which you are using Facebook API for accessing details. Then you have to regenerate token again.

To bypass using Facebook Access Token.

Simply create a facebook App from link and visit your App Dashboard

Copy Your App id and App Secret Key in below url :-<!--Your App Id-->|<!--Your App Secret Key-->

Output will be same

Now simply add an option in above url that is “metadata” and sets value to boolean as shown below<!--Your App Id-->|<!--Your App Token-->&metadata=1

Out will be a long json code with all information related to that id.

Now , if you want to know facebook id is related to page or profile use below function

function get_type_facebook_id_by_devildoxx($app_id, $app_secret_key,$fbid)
    $facebook_g_url = "".$fbid."?access_token=".$app_id."|".$app_secret_key."&metadata=1";

    $get_fb_json_content = file_get_contents($facebook_g_url,true);

    $decode_fb_json_content = json_decode($get_fb_json_content);

    return $decode_fb_json_content->metadata->type;

Call function as below

echo get_type_facebook_id_by_devildoxx(<!--APPID-->, <!--APP_SECRET_KEY-->,<!--FACEBOOKID-->);

Out will be page or user.





Anil Mehra

I am Anil Mehra, a passionate, workaholic and a Full Stack Tech Savvy Programmer with true north towards growth. I have worked on 256 live projects in MNC. I am expertise in the field of Programming, Server Management, SEO, Blogging and SMO...

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

Adblock Detected

Please turn off Ad blocker to view website