protected function updateTwitterPosts() {
if(Sentry::check()) {
$user = Sentry::getUser();
if(in_array('twitter_access_token', ($user->settings->lists('setting')))) {
$settings = array(
'oauth_access_token' => UserSetting::where('user_id', $user->id)->where('setting', 'twitter_access_token')->first()->value,
'oauth_access_token_secret' => UserSetting::where('user_id', $user->id)->where('setting', 'twitter_access_token_secret')->first()->value,
'consumer_key' => Config::get('oauth.twitter_client_id'),
'consumer_secret' => Config::get('oauth.twitter_client_secret')
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$requestMethod = 'GET';
$getfield = '?user_id='.UserSetting::where('user_id', $user->id)->where('setting', 'twitter_id')->first()->value.'&count=10';
$twitter = new TwitterAPIExchange($settings);
$tweets = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$user->twitterPosts()->delete();
foreach (json_decode($tweets) as $tweet) {
$socialPost = new SocialPost();
$socialPost->post_id = $tweet->id_str;
$socialPost->type = 'twitter';
$socialPost->content = $tweet->text;
$socialPost->posted_on = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $tweet->created_at)));
$socialPost->user()->associate($user);
$socialPost->save();
}
return true;
}
}
return Redirect::route('twitterlogin');
}