Validate a Facebook page URL

后端 未结 4 2098
广开言路
广开言路 2020-12-22 02:36

For an application I am developing, we allow users to add a link to their Facebook Page (strictly page, not Profile, not Group, only a Page).

I cannot find anything

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 02:51

    I have the similar task, first I ask Facebook for normalized URL (without !#, etc):

    require_once('facebook.php');
    function getNormalized($anylink){
    $facebook = new Facebook(array(
        'appId'  => 'yourapplicationID',
        'secret' => 'yoursecretcode',
        'cookie' => true,
    ));
    $res = $facebook->api(array(
        'method' => 'fql.query',
        'query' => 'select url, normalized_url from link_stat where url = "'.$anylink.'" ;'
    ));
            if (!isset($res[0]['normalized_url']))
            {
            //If not isset -> set with dumy value, example
            echo '
    You have not entered Facebook Page URL or its not accessible. Please go back and try again.'; exit; } return $res; }

提交回复
热议问题