How to get page id of a facebook page

前端 未结 8 1495
囚心锁ツ
囚心锁ツ 2021-02-19 02:03

I need to fetch page id of a facebook page of a given URL in graph API. e.g this is the URL http://www.facebook.com/platform and I want to get the page id of this facebook page.

8条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 02:42

    The answers given before Oct 27, 2015 no longer work, and the other answer given after that is not dynamic, but requires site scraping. This answer provides the necessary URLs.

    1) Get your App-id and App-secret by choosing an existing app or creating a new one at this url:

    https://developers.facebook.com/apps/
    

    2) Get an access token by making a GET request to this url:

    https://graph.facebook.com/oauth/access_token?client_id=" + APP_ID + "&client_secret=" + APP_SECRET + "&grant_type=client_credentials
    

    3) To get the page-id of your fan page, you need the page-name. Go to your fan page on facebook and look at the url. It will have this form:

    https://www.facebook.com/{fan-page-name}
    

    Once you have that, make a GET request to this url:

    https://graph.facebook.com/{fan-page-name}?access_token={access-token}
    

    It will return a bunch of JSON. You're looking for the first "id" element. This is your page-id.

    See my answer here.

提交回复
热议问题