Is it possible to get Facebook feed, likes and com

2019-02-28 19:34发布

问题:

I want to build a web application that gets feed, likes and comments from a closed group that I own - using the Facebook API + PHP

I saw that I can get information using this Graph API interface, started reading the facebook docs and got to a point that I start thinking that I cant actually do that: https://developers.facebook.com/docs/public_feed/

But still there is this: https://developers.facebook.com/docs/graph-api/reference/v2.2/group/feed

and I just cant find the function that gets the group feed! So maybe I'm just not working right and I'm missing something.

Although when running it on the Facebook API interface it does work! - (https://developers.facebook.com/tools/explorer/145634995501895/)

In older posts, a lot of stackoverflowers recommended me to use the Graph API+PHP and it's completely

Facebook Group Feed PHP SDK

Is it possible to get a facebook feed to a closed group that I belong to but do not own?

This is my code for now, ready to work.

 <?php

    session_start();

  require_once( 'Facebook/FacebookSession.php' );
  require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
  require_once( 'Facebook/FacebookRequest.php' );
  require_once( 'Facebook/FacebookResponse.php' );
  require_once( 'Facebook/FacebookSDKException.php' );
  require_once( 'Facebook/FacebookRequestException.php' );
  require_once( 'Facebook/FacebookAuthorizationException.php' );
  require_once( 'Facebook/GraphObject.php' );
  require_once( 'Facebook/GraphUser.php' );
  require_once( 'Facebook/GraphSessionInfo.php' );

  require_once( 'Facebook/HttpClients/FacebookHttpable.php' );
  require_once( 'Facebook/HttpClients/FacebookCurl.php' );
  require_once( 'Facebook/HttpClients/FacebookCurlHttpClient.php' );
  require_once( 'Facebook/Entities/AccessToken.php' );
  require_once( 'Facebook/Entities/SignedRequest.php' );

  use Facebook\GraphUser;
    use Facebook\FacebookSession;
    use Facebook\FacebookRedirectLoginHelper;
    use Facebook\FacebookRequest;
    use Facebook\FacebookResponse;
    use Facebook\FacebookSDKException;
    use Facebook\FacebookRequestException;
    use Facebook\FacebookAuthorizationException;
    use Facebook\GraphObject;
    use Facebook\Entities\AccessToken;
    use Facebook\HttpClients\FacebookCurlHttpClient;
    use Facebook\HttpClients\FacebookHttpable;


  $app_id = '1408050536103050';
  $app_secret = 'a866372f873730e703cdf0cb4521bd99';
  $redirect_url = 'http://localhost/test/YellowSpider/src/';

    FacebookSession::setDefaultApplication( $app_id, $app_secret );

  //helper for redirect
  $helper = new FacebookRedirectLoginHelper($redirect_url); 

  $session = $helper->getSessionFromRedirect(); //Processes the redirect data from Facebook, if present. Returns a FacebookSession or null.

  if ( isset($session) ){
    // Create request object, execute and capture responce 
    $request = new FacebookRequest($session, 'GET', '/15013584710049696319/feed'); //Represents a request that will be made against the Graph API.

    //From the response - get graph object
    $response = $request->execute(); //Returns a Facebook\FacebookResponse from this request, from which a strongly-typed result can be retrieved. 
                                     //Throws an exception if the request fails. If the error is returned from Facebook, 
                                     //as opposed to a networking issue, a Facebook\FacebookRequestException is thrown.

    $graph = $response->getGraphObject(); //Returns the result as a GraphObject. If specified, a strongly-typed subclass of GraphObject is returned.
    var_dump($graph);


    //use graph object methods to get user details
    //$name = $graph->getname();

    //echo "Hi $name";

  } 
  else {
    echo '<a href="' . $helper->getLoginUrl() . '">Login with Facebook</a>'; 

  }


?>

this is what i get in the var dump:

object(Facebook\GraphObject)[4]
  protected 'backingData' => 
    array (size=0)
      empty

回答1:

There was a missing token and permission definition. This webpage has a simple example of how it suppose to look like:

http://www.benmarshall.me/facebook-sdk-php-v4/