public function handle()
 {
     $request_token = ['token' => $this->userTwitterToken->short_lived_token, 'secret' => $this->userTwitterToken->long_lived_token];
     // $twitter = App::make('Thujohn\Twitter\Twitter');
     $twitter = Twitter::reconfig($request_token);
     $twitterSincePaginatorData = new GetTwitterSinceIdForPagination($this->userTwitterToken->user_id);
     $twitterSinceId = $twitterSincePaginatorData->retrieve();
     $firstCall = $twitterSinceId === 0 ? true : false;
     do {
         $twitterSincePaginatorData = new GetTwitterSinceIdForPagination($this->userTwitterToken->user_id);
         $twitterSinceId = $twitterSincePaginatorData->retrieve();
         $twitterCallParams = array('id' => $this->userTwitterToken->entity_id, 'count' => 100, 'format' => 'json');
         if ($twitterSinceId > 0) {
             $twitterCallParams['since_id'] = $twitterSinceId;
         }
         $checkIfSocialMediaTokenHasFilters = new CheckIfSocialMediaTokenHasFilters($this->userTwitterToken);
         $filter = $checkIfSocialMediaTokenHasFilters->get();
         $tweets = json_decode(Twitter::getUserTimeline($twitterCallParams));
         foreach ($tweets as $tweet) {
             $assignToDB = false;
             if ($filter) {
                 $checkIfTweetHasFilter = new CheckIfTweetHasFilter($tweet->entities->hashtags, $filter->filter);
                 if ($checkIfTweetHasFilter->check()) {
                     $assignToDB = true;
                 }
             } else {
                 $assignToDB = true;
             }
             if ($assignToDB) {
                 $assignTweetsToDb = new AssignTweetsToDatabase($this->userTwitterToken->user_id, $tweet);
                 $assignTweetsToDb->assign();
             }
         }
         $twitterPaginatorData = new GetTwitterMaxIdForPagination($tweets);
         $twitterMaxId = $twitterPaginatorData->extract();
     } while (!$firstCall && count($tweets) > 0);
 }
 public function handle()
 {
     Instagram::setAccessToken($this->userInstagramToken->long_lived_token);
     $morePosts = true;
     $firstCall = true;
     do {
         if (!$firstCall) {
             $posts = Instagram::pagination($posts, 20);
         } else {
             $posts = Instagram::getUserMedia('self', 20);
             $firstCall = false;
         }
         $checkIfSocialMediaTokenHasFilters = new CheckIfSocialMediaTokenHasFilters($this->userInstagramToken);
         $filter = $checkIfSocialMediaTokenHasFilters->get();
         $morePosts = isset($posts->pagination->next_max_id) ? true : false;
         //Check if posts contain any which have already been indexed therefore stop pagination
         $checkIfPostsContainAlreadyExtractedPost = new CheckIfInstagramPostsContainAlreadyExtractedPost($posts->data, $this->userInstagramToken->user_id);
         if ($checkIfPostsContainAlreadyExtractedPost->check()) {
             $morePosts = false;
         }
         foreach ($posts->data as $post) {
             $assignToDB = false;
             if ($filter) {
                 $checkIfPostHasFilter = new CheckIfInstagramPostHasFilter($post->tags, $filter->filter);
                 if ($checkIfPostHasFilter->check()) {
                     $assignToDB = true;
                 }
             } else {
                 $assignToDB = true;
             }
             if ($assignToDB) {
                 $assignInstagramPostsToDb = new AssignInstagramPostsToDatabase($this->userInstagramToken->user_id, $post);
                 $assignInstagramPostsToDb->assign();
             }
         }
     } while ($morePosts);
 }