/** * get facebook profiles feed */ public function actionFeed() { header('Content-Type: application/json; charset=utf-8'); $params = ['limit' => !empty($_GET['limit']) ? (int) $_GET['limit'] : '', 'since' => !empty($_GET['since']) ? $_GET['since'] : null, 'until' => !empty($_GET['until']) ? $_GET['until'] : null, 'fields' => !empty($_GET['fields']) ? $_GET['fields'] : '']; try { $profileDiscovery = new ProfileDiscovery($_GET['profile']); $profile = $profileDiscovery->discovery(); if (!$profile) { $data = json_encode(['error' => ['message' => "Profile '{$_GET['profile']}' not found"]]); Yii::app()->end(json_encode($data), true); } if (!empty($params['until']) && !empty($profile->first_post_date)) { if ($params['until'] >= $profile->first_post_date) { Yii::app()->end(new EFacebookFeedResponse([]), true); } } $feedDiscovery = new FeedDiscovery($profile, $params); $feed = $feedDiscovery->discovery(); if (empty($feed)) { $profile->updateFirstPostDate(); } $response = new EFacebookFeedResponse($feed, $params); $response->setDefaultFields(EFacebookFields::getProfileDefaultFields($profile))->setTimeField($profile->feed_time_field); Yii::app()->end($response, true); } catch (\Exception $e) { $data = json_encode(['error' => ['message' => $e->getMessage()]]); Yii::app()->end(json_encode($data), true); } }
/** * get profile posts from facebook api * * @return mixed */ protected function getRemote() { $fb = Yii::app()->facebook; $params = CMap::mergeArray($this->params, ['fields' => implode(',', EFacebookFields::getPostFields())]); if (isset($params['until'])) { $params['until'] = $params['until'] - 2; } return $fb->getFeed($this->profile->id, $params); }