且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Facebook页面URL中提取页面ID

更新时间:2023-08-25 16:42:46

我想出了一种从任何Facebook页面网址获取页面ID的更好方法,但我不确定是否还有更好的选择,但这是编码我曾经使用过的代码:

I figured out a better way to get page id from any facebook page url, I am not sure if there is even better option to do this but here is the code what I have used:

$fbUrl = "https://www.facebook.com/Lo-stile-di-Anna-1521824524722026";
$graphUrl = "https://graph.facebook.com/?id=".$fbUrl."&access_token=xxxxx&fields=id";
$output = file_get_contents($graphUrl);
$output = json_decode($output, TRUE);
echo $output["id"]; // returns 1521824524722026

我尝试了各种Facebook网址,并且每次都能奏效,希望这对以后的人有所帮助.

I tried this with various facebook urls and it worked everytime, hope this helps someone in the future.