问题描述
我想构建一个 Web 应用程序,该应用程序可以从我拥有的封闭群组中获取提要、点赞和评论 - 使用 Facebook API + PHP
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
我看到我可以使用这个 Graph API 接口获取信息,开始阅读 facebook 文档,但我开始认为我实际上无法做到这一点:https://developers.facebook.com/docs/public_feed/
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/
但是还是有这个: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.
虽然在 Facebook API 接口上运行它时它确实有效!- (https://developers.facebook.com/tools/explorer/145634995501895/)
Although when running it on the Facebook API interface it does work! - (https://developers.facebook.com/tools/explorer/145634995501895/)
在较早的帖子中,很多stackoverflowers推荐我使用Graph API+PHP,而且完全
In older posts, a lot of stackoverflowers recommended me to use the Graph API+PHP and it's completely
是否可以将 Facebook 提要发送给我属于但不拥有的封闭群组?
这是我现在的代码,准备工作.
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>';
}
?>
这是我在 var dump 中得到的:
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 提要、喜欢和评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!