你如何使用Facebook 4.0获得用户的“帖子”?

时间:2014-12-31 02:37:12

标签: php facebook api facebook-graph-api

我正在使用4.0 sdk库,无法弄清楚如何列出“喜欢”我的应用“帖子”的成员。 我可以访问我的电子邮件,生日和其他数据(一次),但不能两次。 如果我选择的话,如何查询我的喜欢,而不仅仅是一次,例如我的电子邮件地址等。?

代码:

<!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( '6350000000851','755000000000009999a0c' );
$helper = new FacebookRedirectLoginHelper('http://mydomain.co/fbauthtest5.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
  $_SESSION['fb_token'] = $session->getToken();
  //$request = new FacebookRequest( $session, 'GET', '/me?fields=post{id,like}');
  $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();

  // print data
  echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
}
else {
    $helper = new FacebookRedirectLoginHelper('http://favd.co/');
    $permissions = array(
        scope =>'publish_actions',
                'email',
                'user_location',
                'user_birthday'
    );

    // Get login URL
    $auth_url = $helper->getLoginUrl($permissions);
    echo "<script>window.top.location.href='".$auth_url."'</script>";

}


?>

</head>

<div
  class="fb-like"
  data-share="true"
  data-width="450"
  data-show-faces="true">
</div>



</body>

</html>

0 个答案:

没有答案