我试图得到最小的例子
using Facebook\FacebookSession;
FacebookSession::setDefaultApplication('YOUR_APP_ID','YOUR_APP_SECRET');
// Use one of the helper classes to get a FacebookSession object.
// FacebookRedirectLoginHelper
// FacebookCanvasLoginHelper
// FacebookJavaScriptLoginHelper
// or create a FacebookSession with a valid access token:
$session = new FacebookSession('access-token-here');
// Get the GraphUser object for the current user:
try {
$me = (new FacebookRequest(
$session, 'GET', '/me'
))->execute()->getGraphObject(GraphUser::className());
echo $me->getName();
} catch (FacebookRequestException $e) {
// The Graph API returned an error
} catch (\Exception $e) {
// Some other error occurred
} …Run Code Online (Sandbox Code Playgroud) 下面的代码位于一个名为facebook_posts.php的文件中,我从索引文件中调用它,如下所示:<?php require_once("http://www.example.com/design/php/facebook_posts.php"); ?>.但是,在放置此代码的地方,没有响应.因此,无论是成功还是捕获错误都不会返回错误(正如我所看到的).我尝试过绝对URL,但这也不起作用.(我隐藏了api和页面信息.)显然,不会加载require_once(页脚和脚本)后面的内容.包含SDK时似乎出现了问题.
我使用的不是作曲家,我需要require的Facebook\文件或use他们?从页面检索帖子需要哪些?
<?php
// Defining FB SDK with absolute paths
define('FACEBOOK_SDK_V4_SRC_DIR', 'http://example.com/design/Facebook/');
require 'http://example.com/design/php/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication('{my-app-id}','{my-app-secret}');
$session = new FacebookSession('{my-long-lived-access-token}');
// Get the GraphUser object for the current user:
try {
$request = new FacebookRequest(
$session,
'GET',
'/{my-page-id}/feed'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
var_dump($graphObject);
echo graphObject;
echo "banana";
} catch (FacebookRequestException $e) {
echo "API ERROR";
} catch (\Exception $e) { …Run Code Online (Sandbox Code Playgroud)