【问题标题】:Is it possible to get Facebook feed, likes and comments from a closed group that I own using the Facebook API + PHP是否可以使用 Facebook API + PHP 从我拥有的封闭群组中获取 Facebook 提要、喜欢和评论
【发布时间】:2015-01-13 07:54:07
【问题描述】:

我想构建一个 Web 应用程序,使用 Facebook API + PHP 从我拥有的一个封闭组中获取 feed、like 和 cmets

我看到我可以使用此 Graph API 接口获取信息,开始阅读 facebook 文档并开始认为我实际上无法做到这一点: https://developers.facebook.com/docs/public_feed/

但还是有这样的: https://developers.facebook.com/docs/graph-api/reference/v2.2/group/feed

而且我就是找不到获取群源的函数! 所以也许我只是工作不正常,我错过了一些东西。

虽然在 Facebook API 接口上运行它时它确实有效! - (https://developers.facebook.com/tools/explorer/145634995501895/)

在较早的帖子中,很多stackoverflowers推荐我使用Graph API + PHP,它完全是

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?

这是我现在的代码,可以使用了。

 <?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>'; 

  }


?>

这是我在 var 转储中得到的:

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

【问题讨论】:

    标签: php facebook api facebook-graph-api facebook-php-sdk


    【解决方案1】:

    缺少令牌和权限定义。 这个网页有一个简单的例子来说明它的外观:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 2015-01-01
      • 2023-03-29
      相关资源
      最近更新 更多