Get Facebook fan page ID

前端 未结 9 1688
名媛妹妹
名媛妹妹 2021-02-04 08:32

I\'ve got the Facebook user ID of the user who created a given page. Now I need to get the page ID to display like box in my website.

Different users have their own Face

9条回答
  •  不知归路
    2021-02-04 09:18

    Here are list of functions which you can add in facebook sdk. Works for both graph api and rest api.

    /*
        Custom functions to get fan page related information
    */
    function getSignedData()
    {
        if(isset($this->signedData) && !empty($this->signedData))
            return $this->signedData;
    
        if(!isset($_REQUEST["signed_request"]))
            return false;
    
        $signed_request = $_REQUEST["signed_request"];
    
        if(empty($signed_request))
            return false;
    
        list($encoded_sig, $payload) = explode('.', $signed_request, 2);
        $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
    
        if(empty($data))
            return false;
    
        $this->signedData = $data;
    
    
    
        return $data;
    }
    
    /*
        Return fan page id, Only return fanpage id for 1st (landing) page of application.
    */
    function getFanPageId()
    {
        if(!$data = $this->getSignedData())
        {
            return false;
        }
        if(isset($data["page"]["id"]))
            return $data["page"]["id"];
    
        return false;
    }
    
    /*
        Only returns userid, if user has authenticated application
    */
    function getFanPageUserId()
    {
        if(!$data = $this->getSignedData())
        {
            return false;
        }
    
        if(isset($data["user_id"]))
        {
            return $data["user_id"];
        }
    
        return false;
    }
    
    /*
    Check if visiting user is fan page admin
    */
    function checkFanPageAdmin()
    {
        if(!$data = $this->getSignedData())
            return false;
    
        if(isset($data["page"]["admin"]) && $data["page"]["admin"] == 1)
            return true;
    
        return false;
    }
    

提交回复
热议问题