-1

I'm trying to get all the reviews from the Facebook page. But some reason, it doesn't get all the reviews.

Php code:

$f1=$fb->get('/me/accounts?access_token='.$user_access_token);
      $id = $f1->getDecodedBody()['data'][0]['id'];
      $access_token = $f1->getDecodedBody()['data'][0]['access_token'];

      $ff1=$fb->get('/'.$id.'/ratings?access_token='.$access_token);

      $facebook_array = $ff1->getDecodedBody()['data'];

      $review = array();
      foreach($facebook_array as $data) {
          $review_text="";
          $pic= $fb->get('/'.$data["reviewer"]["id"].'/picture?access_token='.$access_token)->getHeaders()['Location'];
          if(isset($data['review_text'])){
            $review_text = $data['review_text'];
          }
          $r = array("profile_photo_url"=>$pic,
                 "created_time"=>$data['created_time'],
                 "rating"=>$data['rating'],
                 "reviewer"=>array("name"=>$data['reviewer']['name'],
                                   "id"=>$data['reviewer']['id']),
                 "review_text"=>$review_text);
          array_push($review,$r);
      }
Jows
  • 877
  • 2
  • 11
  • 21

1 Answers1

-1

Just add limit parameter. ?limit=9999

$f1=$fb->get('/me/accounts?access_token='.$user_access_token);
      $id = $f1->getDecodedBody()['data'][0]['id'];
      $access_token = $f1->getDecodedBody()['data'][0]['access_token'];

      $ff1=$fb->get('/'.$id.'/ratings?limit=100&access_token='.$access_token);

      $facebook_array = $ff1->getDecodedBody()['data'];

      $review = array();
      foreach($facebook_array as $data) {
          $review_text="";
          $pic= $fb->get('/'.$data["reviewer"]["id"].'/picture?access_token='.$access_token)->getHeaders()['Location'];
          if(isset($data['review_text'])){
            $review_text = $data['review_text'];
          }
          $r = array("profile_photo_url"=>$pic,
                 "created_time"=>$data['created_time'],
                 "rating"=>$data['rating'],
                 "reviewer"=>array("name"=>$data['reviewer']['name'],
                                   "id"=>$data['reviewer']['id']),
                 "review_text"=>$review_text);
          array_push($review,$r);
      }
Jows
  • 877
  • 2
  • 11
  • 21
  • That still won't get them all if it's over 100. See the comment about Facebook's API and pagination. – ceejayoz Sep 25 '16 at 15:08
  • @ceejayoz Yes, I know, maybe I just need to increase the limit again. That's all I need. Thanks – Jows Sep 25 '16 at 15:41
  • The limit can't be raised over 100. You'll need pagination at that point. – ceejayoz Sep 25 '16 at 15:57
  • @ceejayoz okay. I'll do the pagination. Maybe I just loop it for the next pages. Thanks for the time. – Jows Sep 25 '16 at 16:40