如何使用FB API 4.0执行基本查询以获取帖子上的喜欢?

时间:2015-01-03 21:26:41

标签: facebook api rest facebook-graph-api

我正在尝试执行基本查询以在帖子https://www.facebook.com/explosm/photos/a.427422470475.216607.67400590475/10153591161400476/?type=1&theater上获取相关内容 我的代码没有任何错误,但也没有返回任何值。

如何使用FB API 4.0执行基本查询以获取帖子上的内容?

<!DOCTYPE html>
<html>
<body>

<head>

<?php
session_start();
// added in v4.0.0
require_once 'facebook-php-sdk-v4/autoload.php';

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;

FacebookSession::setDefaultApplication( '1111111111111','22222222222222222222222' );
    $helper = new FacebookRedirectLoginHelper('http://favd.co/fbauthtest.php' );

try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}

if ( isset( $session ) ) {
  // graph api request for user data
  $request = new FacebookRequest( $session, 'GET', '/me/likes' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();

  // print data
  echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
} else {
  // show login url
  echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
}


/*
$request = new FacebookRequest(
  $session,
  'GET',
  //'/me/likes'
        '/fql?q=SELECT%10153591170640476%20FROM%20like%20WHERE%20object_id=427422470475%20%LIMIT=1000'
);

$response = $request->execute();
$graphObject = $response->getGraphObject();
*/



?>

</head>



</body>

</html>

1 个答案:

答案 0 :(得分:0)