How do I get Facebook page username or facebook page ID from url

你离开我真会死。 提交于 2019-12-06 04:13:22

问题


I've made a website where users can submit their Facebook page and I orginally coded it assuming that they would of set up a vanity URL for their page. E.g.

http://www.facebook.com/myfacebookpage

But I forgot that some pages can have urls such as

http://www.facebook.com/pages/myfacebookpage/54878424154545487

My question is how do I use PHP to grab the part of the url in bold?

Thanks!


回答1:


like this:

$url='http://www.facebook.com/pages/myfacebookpage/54878424154545487'; // the input
$pieces = explode('/', $url); // divides the string in pieces where '/' is found
$key=end($pieces); //takes the last piece



回答2:


You can just recode your application to use https://graph.facebook.com/?ids=

Which will take both

  • http://www.facebook.com/myfacebookpage and
  • http://www.facebook.com/pages/myfacebookpage/54878424154545487

Examples

  • https://graph.facebook.com/?ids=https://www.facebook.com/boo
  • https://graph.facebook.com/?ids=https://www.facebook.com/pages/phwd/113702895386410


来源:https://stackoverflow.com/questions/16884295/how-do-i-get-facebook-page-username-or-facebook-page-id-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!