是否可以从使用Facebook API + PHP的我所拥有的封闭组中获取Facebook Feed,喜欢和评论 [英] Is it possible to get Facebook feed, likes and comments from a closed group that I own using the Facebook API + PHP

查看:151
本文介绍了是否可以从使用Facebook API + PHP的我所拥有的封闭组中获取Facebook Feed,喜欢和评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个网络应用程序,从我拥有的封闭组中获取Feed,喜欢和评论 - 使用Facebook API + PHP



我看到我可以使用Graph API界面获取信息,开始阅读facebook文档,并开始认为我无法实际执行此操作:
https://developers.facebook.com/docs/public_feed/



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



我只是找不到该组的功能feed!
所以也许我只是不正常,我错过了一些东西。



虽然在Facebook API界面上运行时它可以正常工作! - ( https://developers.facebook.com/tools/explorer/145634995501895/



在较旧的帖子中,很多stackoverflowers建议我使用Graph API + PHP,它完全是



Facebook Group Feed PHP SDK



是否可以得到一个我所属但不拥有的封闭组的Facebook Feed?



这是我现在的代码,准备上班了。

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

使用Facebook\GraphUser;
使用Facebook\FacebookSession;
使用Facebook\FacebookRedirectLoginHelper;
使用Facebook\FacebookRequest;
使用Facebook\FacebookResponse;
使用Facebook\FacebookSDKException;
使用Facebook\FacebookRequestException;
使用Facebook\FacebookAuthorizationException;
使用Facebook\GraphObject;
使用Facebook\Entities\AccessToken;
使用Facebook\HttpClients\FacebookCurlHttpClient;
使用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(); //处理来自Facebook的重定向数据(如果存在)。返回一个FacebookSession或null。

if(isset($ session)){
//创建请求对象,执行并捕获responce
$ request = new FacebookRequest($ session,'GET',' 15013584710049696319 /进料'); //表示将针对Graph API进行的请求。

//从响应 - 获取图形对象
$ response = $ request-> execute(); //从此请求返回一个Facebook\FacebookResponse,从中可以检索强类型的结果。
//如果请求失败,则抛出异常。如果从Facebook返回错误
//而不是网络问题,则会抛出一个Facebook \FacebookRequestException。

$ graph = $ response-> getGraphObject(); //返回结果作为GraphObject。如果指定,则返回一个强类型的GraphObject子类。
var_dump($ graph);


//使用图形对象方法获取用户详细信息
// $ name = $ graph-> getname();

// echoHi $ name;

}
else {
echo'< a href ='。$ helper-> getLoginUrl()。'>使用Facebook登录< / a> ;

}


?>

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

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


解决方案>

有一个丢失的令牌和权限定义。
这个网页有一个简单的例子,说明如何看起来像:



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


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

解决方案

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/

这篇关于是否可以从使用Facebook API + PHP的我所拥有的封闭组中获取Facebook Feed,喜欢和评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆