douniewei6346 2014-10-20 13:06
浏览 26
已采纳

使用PHP SDK从Facebook Group存储Feed [关闭]

I have a project that needs me to store a group feed of one of my Facebook groups that I want to store locally (MySQL). I have used PHPs Facebook SDK to successfully retrieve and store the first 24 posts. The rest are paginated like, as seen in the response:

"paging": {
    "previous": "https://graph.facebook.com/v2.1/197349856967661/feed?limit=25&since=1413803847&__paging_token=enc_Aezfg88j7xOEW28BENBXvchQql9OYz00t6siBT2MviwZdOCcIFV8nyMyBmrUu39eOHbve68h6yUWLb0Lc12v_HD7k4_q299PnvIq7gz4BAZMZA", 
    "next": "https://graph.facebook.com/v2.1/197349856967661/feed?limit=25&until=1413803553&__paging_token=enc_AeyKAdBaClRXLJ7nBulYeqDEfzW1ovuAXSuDkPMSnbmIxpPXKh24vli0tOpF_OOtnFCXZLNTZki3j2umR8WKKyo3nLmZtICF1zfq7ZASIk2PdQ"
}

I wanted to know if there was a way in which I can loop the same piece of code until all the entries have been stored in my database. I am thinking is there a way to detect if there is a next page and execute another request using the "next" URL? Please do help me. I will highly appreciate it.

  • 写回答

1条回答 默认 最新

  • douying4909 2014-10-20 13:22
    关注

    Disclaimer: I am going to give you the procedure not the code, you can code it based on what you need.

     login.
     make the first request. //don't handle just yet.
     if (![paging][next]) escapeLoop =1;
     do  //using do .. while
        if (escapeLoop ==1) break; //exits loop if all posts are received in one page
        handle the request   //insert to DB
        make the new request using the link provided in the response.
     while ([paging][next]);
     handle the last request & requests with one page response.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号