Get wall feed from a public Facebook page using Graph API - is it really this complex?

前端 未结 3 686
悲哀的现实
悲哀的现实 2021-02-04 08:27

I have started off by reading Displaying Facebook posts to non-Facebook users which is of some use but I cannot believe it is this difficult to get a public feed from Facebook.<

3条回答
  •  逝去的感伤
    2021-02-04 08:50

    Two years later, you can programmatically do this with a Facebook App (an example using PHP and Slim): https://developers.facebook.com/apps/

    $base_api="https://graph.facebook.com/";
    $client_id="XXXXXX";
    $app_secret="XXXXXX";
    
    //get a profile feed (can be from a page, user, event, group)
    $app->get('/feed/:profileid/since/:start_date', function ($profile_id,$start_date) {
    
        $start_time=date('m/d/Y h:i:s',$start_date);
    
        $request = new FacebookRequest(
          getSession(),
          'GET',
          '/'.$profile_id.'/feed?since='.$start_time
        );
    
        $response = $request->execute();
        $graphObject = $response->getGraphObject();
    
        //do something with $graphObject
    
    });
    
    
    function getSession(){
        $session = new FacebookSession(getAccessToken());
        return $session;
    }
    
    
    function getAccessToken(){
        global $base_api, $client_id, $app_secret;
        $url=$base_api."oauth/access_token?client_id=".$client_id."&client_secret=".$app_secret."&grant_type=client_credentials";
        $str = file_get_contents($url);
        $token = str_replace ( "access_token=" , "" , $str );
        return $token;
    }
    

提交回复
热议问题