facebook分页使用next()URL错误

时间:2017-08-02 10:13:56

标签: php facebook-graph-api pagination

我正在研究facebook分页,我搜索过但没有得到相关答案。 首先我获取10个结果,然后在onclick函数后我想获取接下来的10个结果,我正在通过 -

[paging] =>

阵 (

    [previous] => https://graph.facebook.com/v2.9/....D&__previous=1

    [next] => https://graph.facebook.com/........

作为参数,我也尝试传递下一个URL作为参数,但仍然无法正常工作,如果我将$ feedEdge作为关联传递我得到的响应为null,下面是我的代码

$response = self::$_FBINSTANCE->get('/me/feed?fields=id,message&limit=' . $_pagination->limit); 

        if(empty($_nextFeed)){ 
            $feedEdge = $response->getGraphEdge();
            $nextFeed = $response->getGraphEdge()->getMetaData();
        }else{
            $feedEdge=$response->next($_nextFeed);
            $nextFeed = $response->getGraphEdge()->getMetaData();
        }
        $result = array();
        foreach ($feedEdge as $status) {
          $result[] = $status->asArray();
        }  
        return array(
            'result'    => $result,
            'totalRows' => $totalCount,
            'nextFeed'  => $nextFeed
        );

使用v2.9版本,我应该为$ response-> next()传递什么参数;如果我错了,请帮助我。

1 个答案:

答案 0 :(得分:0)

我找到了这个问题的解决方案......

如果有人尝试下面的代码尝试相同的尝试。

        $result = array();
        if(empty($_nextFeed)){ 
            $response = $fb->get('/me/feed?fields=id,message&limit=' . $_pagination->limit); 
            $feedEdge = $response->getGraphEdge();

            foreach ($feedEdge as $status) {
                $result[] = $status->asArray();
            }

            $nextFeed = $response->getGraphEdge()->getMetaData();
        }else{
            //to get until time stamp form next url
            $nextURl=parse_url($_nextFeed['paging']['next']);
            parse_str($nextURl['query'], $URL);

            $response = $fb->get('/me/feed?fields=id,message&limit='.(($_pagination->limit)+1).'&until='.$URL['until']); 
            $feedEdge = $response->getGraphEdge();

            foreach ($feedEdge as $status) {
                $result[] = $status->asArray();                    
            }
            //because result repeats last array of previous request
            array_splice($result,0,1);

            $nextFeed = $response->getGraphEdge()->getMetaData();
        }

        return array(
            'result'    => $result,
            'totalRows' => $totalCount,
            'nextFeed'  => $nextFeed
        );

有效:)