【发布时间】:2021-05-28 07:30:01
【问题描述】:
使用 facebook php sdk,我正在尝试使用“名称、网站、解密...”等数据检索我的所有页面
- 我使用 facebook javascript api 登录(我已要求提供所需的权限)并检索了用户令牌
$fb = new \Facebook\Facebook([
'app_id' => $app_id,
'appsecret_proof' => $appsecret_proof,
'app_secret' => $app_secret,
'default_graph_version' => 'v5.0',
]);
$pagesResponse = $fb->get('/me/accounts', $access_token);
$pages_php=[];
$pagesEdge = $pagesResponse->getGraphEdge();
$pagesDecoded = json_decode($pagesEdge);
foreach ($pagesDecoded as $page) {
$id=$page->id;
$response = $fb->get(
'/'.$id.'/locations?fields=name%2Cbio%2Cdescription',
$access_token
);
//the following line returns an error 'Unable to convert response from Graph to a GraphNode'
//$graphNode = $response->getGraphNode();
//the following line return an array containing only the request without page data
$graphNode = $response->getGraphEdge();
}
- 然后我检索了我正在管理的页面 ID,但是当我尝试使用 /{page-id}/locations 端点获取页面数据时,getGraphNode 返回错误,因此我使用了 getGraphEdge /{page-id}/locations 端点它返回一个没有页面数据的数组
Facebook\GraphNodes\GraphEdge::__set_state(array(
'request' =>
Facebook\FacebookRequest::__set_state(array(
'app' =>
Facebook\FacebookApp::__set_state(array(
'id' => '******************',
'secret' => '******************',
)),
'accessToken' => '****************************************',
'method' => 'GET',
'endpoint' => '/{page-id}/locations?fields=name%2Cbio%2Cdescription%2Cwebsite',
'headers' =>
array (
'Content-Type' => 'application/x-www-form-urlencoded',
),
'params' =>
array (
),
'files' =>
array (
),
'eTag' => NULL,
'graphVersion' => 'v5.0',
)),
'metaData' =>
array (
),
'parentEdgeEndpoint' => NULL,
'subclassName' => NULL,
'items' =>
array (
),
));
【问题讨论】:
-
还有——你有没有按照错误信息告诉你的去做……?
-
这一行触发错误$response->getGraphNode()
-
这和文档一模一样!但似乎 sdk 正在返回图形边缘而不是图形节点,因此无法检索页面数据(名称位置..)
-
感谢您的回复,是的,我得到了托管页面 ID 的 $pagesResponse = $fb->get('/me/accounts', $access_token); $pages_php=[]; $pagesEdge = $pagesResponse->getGraphEdge();这不会返回所有必填字段,例如页面网站、页面描述......为此我需要调用 /{page-id}/locations 端点,这预计会返回一个图形节点,但它实际上正在返回图边!所以页面数据仍然无法访问!
标签: php laravel facebook-graph-api facebook-sdk-4.0