我有这个代码,以便检索最后5位Facebook用户发布并在其他网站上发布
require_once 'Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => '{xxxxxxxxxxxx}',
'app_secret' => '{xxxxxxxxxxxxxx}',
'default_graph_version' => 'v2.2',
]);
try {
$response = $fb->get('/me/feed?fields=id,message&limit=5');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// Page 1
$feedEdge = $response->getGraphEdge();
foreach ($feedEdge as $status) {
var_dump($status->asArray());
}
// Page 2 (next 5 results)
$nextFeed = $fb->next($feedEdge);
foreach ($nextFeed as $status) {
var_dump($status->asArray());
}
错误消息是: 图表返回错误:必须使用活动访问令牌来查询有关当前用户的信息
有人可以帮助我吗?
先谢谢
更新 我更改了代码:
require_once 'Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => '{*****}',
'app_secret' => '{******}',
'default_graph_version' => 'v2.6',
]);
try {
$tolken = $fb->get("/oauth/access_token?client_id={****}&client_secret={***********}&grant_type=client_credentials");
$response = $fb->get("/me/feed?fields=id,message&limit=5&access_token=$tolken");
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// Page 1
$feedEdge = $response->getGraphEdge();
foreach ($feedEdge as $status) {
var_dump($status->asArray());
}
// Page 2 (next 5 results)
$nextFeed = $fb->next($feedEdge);
foreach ($nextFeed as $status) {
var_dump($status->asArray());
}
现在错误是: 图表返回错误:缺少redirect_uri参数
但是在dashboARd / setting / advanced中,我已经设置了' URI di reindirizzamento OAuth validi' ....