我正在尝试获取使用php的用户朋友的列表,但它一直抛出异常,对于开发人员docs,代码与Facebook相同 https://developers.facebook.com/docs/graph-api/reference/v3.0/user/friends
这是我的代码
$fb = new \Facebook\Facebook([
'app_id' => APP_ID,
'app_secret' => APP_SECRET,
'default_graph_version' => DEFAULT_GRAPH_VERSION,
//'access_token' => '{'.$fbToken.'}', // optional
]);
try {
$response = $fb->get('/friends', $fbToken);
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
这是错误的堆栈跟踪
[03-Jul-2018 07:29:33 UTC] PHP Fatal error: Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Unable to convert response from Graph to a GraphNode because the response looks like a GraphEdge. Try using GraphNodeFactory::makeGraphEdge() instead.' in /facebook/Facebook/GraphNodes/GraphNodeFactory.php:224
Stack trace:
#0 /facebook/Facebook/GraphNodes/GraphNodeFactory.php(93): Facebook\GraphNodes\GraphNodeFactory->validateResponseCastableAsGraphNode()
#1 /facebook/Facebook/FacebookResponse.php(289): Facebook\GraphNodes\GraphNodeFactory->makeGraphNode(NULL)
#2 {main}
thrown in /facebook/Facebook/GraphNodes/GraphNodeFactory.php on line 224
答案 0 :(得分:1)
尝试以下方法:
$graphNode = $response->getGraphEdge();
很老,所以我没有将其标记为重复项:FB Graph API query doesn't work in PHP SDK