下载facebook sdk for php后,我尝试运行following。代码是:
function QueryToRetrieveUserThroughID(string $id) {
$newFacebookApp = new Facebook\FacebookApp(app-id, app-secret);
$request = new Facebook\FacebookRequest(
$newFacebookApp, 'GET', '/' . $id
);
$response = $request->execute();
$graphObject = $request->getGraphObject();
}
虽然到达$response = $request->execute();
行时会产生:
Fatal error: Uncaught Error: Call to undefined method Facebook\FacebookRequest::execute()
我在这里做错了如何使用API的想法或者确实FacebookRequest :: execute不存在?
答案 0 :(得分:5)
Facebook SDK for PHP上Issue #509的Facebook for Developers页面实际上是一个问题,其中页面上的示例代码实际上是针对SDK v4的,因此在v5上使用时会产生错误。
最新文档托管在https://github.com/facebook/php-graph-sdk/blob/5.5/docs/reference.md。
使用SDK v5:
// PHP GRAPH SDK 5.5
function QueryToRetrieveUserThroughID(string $id) {
$newFacebook = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.5',
]);
$newFacebookApp = $newFacebook->getApp();
$response = $newFacebook->get($id, '{access-token}');
// or $response = $newFacebook->get($id);
$graphObject = $response->getGraphObject();
}