是否有可能获得Facebook的饲料,喜欢从一个封闭的群体的意见,我自己使用Facebook API + PHP [英] Is it possible to get Facebook feed, likes and comments from a closed group that I own using the Facebook API + PHP

查看:183
本文介绍了是否有可能获得Facebook的饲料,喜欢从一个封闭的群体的意见,我自己使用Facebook API + PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个Web应用程序,获取的饲料,喜欢和我拥有一个封闭的群体的意见 - 使用Facebook API + PHP

我看到了,我可以用这个图形API接口获取信息,开始阅读Facebook的文档,并得到了,我开始思考,我不能真正做到这一点:
https://developers.facebook.com/docs/public_feed/

但仍有这样的:
https://developers.facebook.com/docs/graph -API /参考/ V2.2 /组/供稿

我只是不能找到获取组饲料的功能!
所以,也许我只是不工作的权利,我失去了一些东西。

虽然Facebook的API接口上运行时,它的工作! - ( https://developers.facebook.com/tool​​s/explorer/145634995501895/

在旧帖子,很多stackoverflowers的建议我使用图形API + PHP和它是完全

Facebook群组订阅PHP SDK

<一个href=\"http://stackoverflow.com/questions/16816436/is-it-possible-to-get-a-facebook-feed-to-a-closed-group-that-i-belong-to-but-do\">Is有可能得到一个Facebook饲料一个封闭的群体,我属于,但不拥有?

这是我的code现在,做好准备工作。

 &LT; 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 /实体/ AccessToken.php');
  require_once(的Facebook /实体/ SignedRequest.php');  使用Facebook \\ GraphUser;
    使用Facebook \\ FacebookSession;
    使用Facebook \\ FacebookRedirectLoginHelper;
    使用Facebook \\ FacebookRequest;
    使用Facebook \\ FacebookResponse;
    使用Facebook \\ FacebookSDKException;
    使用Facebook \\ FacebookRequestException;
    使用Facebook \\ FacebookAuthorizationException;
    使用Facebook \\ GraphObject;
    使用Facebook \\实体\\的accessToken;
    使用Facebook \\ HttpClients \\ FacebookCurlHttpClient;
    使用Facebook \\ HttpClients \\ FacebookHttpable;
  $ APP_ID ='1408050536103050';
  $ app_secret ='a866372f873730e703cdf0cb4521bd99';
  $ REDIRECT_URL =的http://本地主机/测试/ YellowSpider / src目录/';    FacebookSession :: setDefaultApplication($ APP_ID,$ app_secret);  //帮手重定向
  $帮手=新FacebookRedirectLoginHelper($ REDIRECT_URL);  $会议= $ helper-&GT; getSessionFromRedirect(); //流程从Facebook重定向数据,如果present。返回FacebookSession或空。  如果(使用isset($会话)){
    //创建请求对象,执行和捕获的反响
    $ =请求新FacebookRequest($会议上,GET,/ 15013584710049696319 /进料'); //重新presents,将针对图形API进行的请求。    //从响应 - 获取图形对象
    $响应= $请求 - &GT;执行(); //从这个请求,从一个强类型的结果可以被检索返回一个Facebook \\ FacebookResponse。
                                     //如果请求失败,则会引发异常。如果从Facebook返回的错误,
                                     //,而不是一个网络问题,一个Facebook \\ FacebookRequestException被抛出。    $图表= $响应 - &GT; getGraphObject(); //返回结果作为GraphObject。如果指定,则返回GraphObject的强类型的子类。
    后续代码var_dump($图)
    //使用图形对象的方法来获取用户详细信息
    // $名称= $ graph-&GT;的getName();    //回声你好$名称;  }
  其他{
    呼应'&LT; A HREF ='$ helper-方式&gt; getLoginUrl()。'&GT;登录Facebook和LT; / A&GT;';  }
?&GT;

这是我在var转储得到:

 对象(脸谱\\ GraphObject)[4]
  保护'backingData'=&GT;
    阵列(大小= 0)
      空


解决方案

有是一个缺少令牌和权限的定义。
此网页有它是如何想看起来像一个简单的例子:

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的饲料,喜欢从一个封闭的群体的意见,我自己使用Facebook API + PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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