我想构建一个Web应用程序,使用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,它完全
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