public fetchTwitterStats ( ) : array | Illuminate\View\View | ||
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();
}
}
/** * Update stats in DB (like count & retweet count) * * @return void */ public function updateTwitterStats() { $tweets = $this->twitterContent->fetchTwitterStats(); foreach ($tweets as $key => $tweet) { if ($this->publishment->where('tweet_id', $tweet['id_str'])->exists()) { $publishment = $this->publishment->where('tweet_id', $tweet['id_str'])->first(); $publishment->twitter_likes = $tweet['favorite_count']; $publishment->twitter_retweets = $tweet['retweet_count']; $publishment->save(); } } $this->log->updateLog('publishments'); }