我正试图从我的Facebook页面上获取帖子,我现在已经登录了,就像这样:
try {
$response = $fb->get('/me/posts', $accessToken->getValue);
} 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;
}
var_dump($response->getDecodedBody());
getDecodedBody
返回
array(size = 1)'data'=> 数组(大小= 0) 空
或者像这样
$json_object = file_get_contents('https://graph.facebook.com/me/posts?&access_token=' . $accessToken->getValue());
$posts = json_decode($json_object);
var_dump($posts);
我得到了相同的结果。
更新
我使用javascript创建了访问令牌
window.onload = function() {
FB.login(function(response) {
if (response.authResponse) {
//alert('You are logged in & cookie set!');
// Now you can redirect the user or do an AJAX request to
// a PHP script that grabs the signed request from the cookie.
location.href = 'http://localhost/FB/js-login.php';
} else {
alert('User cancelled login or did not fully authorize.');
}
});
return false;
};
window.fbAsyncInit = function() {
FB.init({
appId: '123450723574945',
cookie: true, // This is important, it's not enabled by default
version: 'v2.2'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
在php中得到它
$helper = $fb->getJavaScriptHelper();
$accessToken = $helper->getAccessToken();
var_dump($accessToken)
结果:
对象(脸谱\认证\的accessToken)[13]
protected'value'=> 字符串'EAABrvUukr0EBAH8yuJpQkhdkZCZBW'(长度= 207)
protected'expiresAt'=> 对象(日期时间)[15] public'date'=>字符串'2017-06-08 16:00:00.000000'(长度= 26) public'timezone_type'=> int 3 public'timezone'=>字符串'UTC'(长度= 3)
正如我所看到的,expiresAt
属性约束的时间少于现在,但我没有任何错误消息。