Jows
Jows

Reputation: 897

Php Facebook API not pulling all reviews

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);
      }

Upvotes: -1

Views: 352

Answers (1)

Jows
Jows

Reputation: 897

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);
      }

Upvotes: -1

Related Questions