我如何使用图形API解析来自Facebook的数据

时间:2014-12-11 14:45:59

标签: facebook facebook-graph-api

我正在用正确的信息填充它。为什么它告诉我你的应用程序ID无效???

app秘密在这里我是假的,但它的真实在脚本中。告诉我应该怎么做

      <?php
session_start();
// added in v4.0.0
require_once 'vendor/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;

// start session

// init app with app id and secret
FacebookSession::setDefaultApplication( '425591634259397','5e5789c1b17394a42c4595dssfa8b4591d0' );

$session = new FacebookSession('425591634259397|5e5789c1b1739dds4a42c4595fa8b4591d0');
if ( isset( $session ) ) {
    // graph api request for user data
    $request = new FacebookRequest( $session, 'GET', '/972293049466394/feed' );

    $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>';
}
?>

1 个答案:

答案 0 :(得分:0)

“App Access Token”足以读取Page Feed。使用PHP:

$accessToken = APP-ID . '|' . APP-SECRET;

有关Page Feed的示例代码和信息:https://developers.facebook.com/docs/graph-api/reference/v2.2/page/feed

有关所有访问令牌的信息:https://developers.facebook.com/docs/facebook-login/access-tokens/

另一个关于访问令牌的链接:http://www.devils-heaven.com/facebook-access-tokens/