/**
  * Fetch user's tweets
  *
  * @return array|\Illuminate\View\View
  */
 public function fetchTwitterStats()
 {
     $client = initTwitter();
     $twitterId = $this->config->twitterId();
     try {
         $tweets = $client->get('statuses/user_timeline.json?user_id=' . $twitterId);
         return json_decode($tweets->getBody(), true);
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         getErrorMessage($e->getResponse()->getStatusCode());
         return back();
     }
 }
Example #2
0
 /**
  * Insert reaction in DB (eiter from a Facebook post or Tweet)
  * @param  string $type
  * @param  object $mention
  * @param  integer $id
  * @param  string $answer
  *
  * @return Reaction
  */
 public function insertReaction($type, $mention, $id, $answer = null)
 {
     $reaction = new Reaction();
     $reaction->publishment_id = $id;
     if ($answer != null) {
         $reaction->user_id = Auth::user()->id;
     }
     if ($type == 'twitter') {
         if ($mention['user']['id_str'] != Configuration::twitterId()) {
             $reaction->user_id = $mention['user']['id_str'];
         }
         $reaction->screen_name = $mention['user']['screen_name'];
         $reaction->tweet_id = $mention['id_str'];
         $reaction->tweet_reply_id = $mention['in_reply_to_status_id_str'];
         $reaction->message = $mention['text'];
         $reaction->post_date = changeDateFormat($mention['created_at']);
     } else {
         $reaction->fb_post_id = $mention->id;
         if ($answer == null) {
             $reaction->screen_name = $mention->from->name;
             $reaction->message = $mention->message;
             $reaction->post_date = changeFbDateFormat($mention->created_time);
         } else {
             $reaction->message = $answer;
             $reaction->post_date = Carbon::now();
         }
     }
     $reaction->save();
     return $reaction;
 }