如何使用PHP SDK v4获取/me/feed [英] How do you get /me/feed using PHP SDK v4
问题描述
我正在使用最新版本的Facebook PHP SDK v4.0.12.我正在尝试使用SDK抓取我的供稿.我已经安装了SDK,并且可以正常工作.
I'm using the latest version of the Facebook PHP SDK v4.0.12. I'm trying to grab my feed using the SDK. I have the SDK setup and working properly.
我从以下示例代码开始:
I started with this example code:
// save the session
$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
$session = new FacebookSession( $session->getToken() );
// graph api request for user data
$request = (new FacebookRequest(
$session,
'GET',
'/me'
))->execute()->getGraphObject(GraphUser::className());
var_dump($request);
所有这些都很好,我可以看到我的姓名,年龄,性别等.该请求没有问题.
All of that works great, i can see my name, age, gender, etc. No problems with that request.
我想我应该能够使用相同的代码并做一个细微的改动就获得我的/me/feed.
I think i should be able to get my /me/feed using this same code with one subtle change.
// save the session
$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
$session = new FacebookSession( $session->getToken() );
// graph api request for user data
$request = (new FacebookRequest(
$session,
'GET',
'/me/feed'
))->execute()->getGraphObject(GraphUser::className());
var_dump($request);
但是,不幸的是,这不起作用.我得到一个空数组,或者正如其他人在此处所述,他们看到"object(Facebook \ GraphUser)#334(1){["backingData":protected] => array(0){}}".我发现的类似问题并没有完全回答我.我已经尝试了一些方法,但是运气不佳.
But, unfortunately, this does not work. I get an empty array or as others have stated on here they see "object(Facebook\GraphUser)#334 (1) { ["backingData":protected]=> array(0) { } }". The similar questions i had found didnt quite answer it for me. I've tried a few things, but not having much luck.
更新#2-回复下面的评论
我的登录链接如下:
echo '<a href="' . $helper->getLoginUrl( array( 'user_status,read_stream' ) )
. '" target="_top">Login</a>';
我尝试注销,然后重新登录以希望重置权限.
I've tried logging out and then logging back in to hopefully reset the permissions.
我也尝试过:
// graph api request for user data
$request = (new FacebookRequest(
$session,
'GET',
'/me/feed'
))->execute()->getGraphObject()->asArray();
这将输出一个空白数组.
This outputs a blank array.
推荐答案
由于我仅在评论中回答过,所以这才是真正的答案:
Since i´ve answered it in the comments only, here´s the real one:
您需要通过检出调试器.
顺便说一句,在使用read_stream创建任何应用程序之前,请先阅读以下内容: https://developers.facebook.com/docs/facebook-login/permissions/v2.2#reference-read_stream
Btw, read this before creating any App with read_stream: https://developers.facebook.com/docs/facebook-login/permissions/v2.2#reference-read_stream
这篇关于如何使用PHP SDK v4获取/me/feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!