facebookRequest :: execute()未包含在Facebook SDK中 [英] FacebookRequest::execute() not included in facebook sdk
问题描述
下载用于php的facebook sdk 我试图运行以下.代码是:
After downloading facebook sdk for php i tried to run the following. The code is:
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();
时它会产生:
Though when reaching the line $response = $request->execute();
it produces:
Fatal error: Uncaught Error: Call to undefined method Facebook\FacebookRequest::execute()
我在这里做错什么了,是关于如何使用API的想法,或者实际上不存在FacebookRequest :: execute吗?
Am i doing something wrong here with the idea of how to use the API or indeed FacebookRequest::execute does not exist??
推荐答案
实际上,这是Facebook开发人员页面上适用于PHP的Facebook SDK ,如问题#509中所述,其中页面上的示例代码实际上是针对SDK v4的,因此在v5上使用时会产生错误.
It is actually an issue on Facebook for Developers page for Facebook SDK for PHP as described on Issue #509 wherein the sample codes on the page are actually for SDK v4, thus producing errors when used on 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();
}
这篇关于facebookRequest :: execute()未包含在Facebook SDK中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!