function PostImage() { if (!isset($_POST['source']) || $_POST['source'] == "") { return "Missing required params"; } $config = (include "/config.php"); $source = $_POST['source']; $final = ""; if (isset($_POST['message'])) { $orig = $_POST['message']; $final = FilterText($orig); } $access_token = $_SESSION['access_token']; $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $check = new TB_Twitter_Check(); if (!$check->VerifyTweet($source, $final)) { return "Tweet is not valid"; exit; } $media1 = $connection->upload('media/upload', array('media' => $source)); $parameters = array('status' => $final, 'media_ids' => implode(',', array($media1->media_id_string))); $result = $connection->post('statuses/update', $parameters); if ($connection->getLastHttpCode() == 200) { return "success"; } else { return "An unnknown error occured"; } }
public function refresh() { $oauth = new TwitterOAuth(\twitter\configuration::$consumerKey, \twitter\configuration::$consumerSecret); $accessToken = $oauth->oauth2('oauth2/token', ['grant_type' => 'client_credentials']); $this->twitter = new TwitterOAuth(\twitter\configuration::$consumerKey, \twitter\configuration::$consumerSecret, null, $accessToken->access_token); $this->update(); }
function getTweets($notification) { $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $date = $notification['date']; $keywords = array("sirene", "gevaar", "ongeluk", "ambulance", "ziekenwagen", "ongeval", "gewond", "letsel", "brand", "vlam", "vuur", "brandweer", "blus", "water", "overval", "politie", "dief", "wapen", "letsel", "inbraak", "schiet", "misdrijf"); $start_date = "since:" . date(DATE_FORMAT, $date); $end_date = "until:" . date(DATE_FORMAT, strtotime("+1 day", $date)); //$search_string = $notification['town'] . " " . implode(" OR ", $keywords) . " -p2000 " . $start_date . " " . $end_date; $search_string = implode(" OR ", KEYWORDS_GEN) . " -p2000 -RT " . $start_date . " " . $end_date; $cur_min = min(100, $notification["num_tweets"]); $params = array('q' => $search_string, 'lang' => 'nl', 'count' => $cur_min); //$statuses = json_encode((array)$twitter->get("search/tweets", $params)); $temp = (array) $twitter->get("search/tweets", $params); $statuses = $temp["statuses"]; $total_num = count($statuses); $num_stat = count($statuses); $min_id = $statuses[$num_stat - 1]->id; while ($total_num < $notification["num_tweets"] && $num_stat >= $cur_min) { $cur_min = min($notification["num_tweets"] - $total_num, 100); $params = array('q' => $search_string, 'lang' => 'nl', 'count' => $cur_min, 'max_id' => $min_id); $new_temp = (array) $twitter->get("search/tweets", $params); $new_stat = $new_temp["statuses"]; $num_stat = count($new_stat); $total_num = $total_num + $num_stat; $min_id = $new_stat[$num_stat - 1]->id; $statuses = array_merge($statuses, $new_stat); } //What do I do with the statuses? return json_encode($statuses); }
public function getLongLat($query) { $GEOdatax = ""; $GEOdata = ""; if ($query != NULL) { $consumer = "3Hsr7qk9HEYseF9bpJA07Go6H"; $consumersecret = "q1TjkWCHcPKrJn0YCmtKMwIHaXURI7ip3z5eDxDd4G0GxLsUOi"; $accesstoken = "3803581341-FAlmx3CbE2amgcMyD2AkGYuLdRa7kZ3QcDSxj5a"; $accesstokensecret = "1JtROKIjMaIhP6IJGMPGbTyRTF9WMyq1RGclpdvcKzZWD"; $twitter = new TwitterOAuth($consumer, $consumersecret, $accesstoken, $accesstokensecret); $url = "geo/search"; $GEOquery = $twitter->get($url, array('query' => $query, 'granularity' => 'city', 'max_results' => '1')); foreach ($GEOquery->result->places as $GEOresult) { $GEOdata = $GEOresult->centroid; $GEOtype = $GEOresult->place_type; } if ($GEOdata != NULL) { $GEOdatax = implode(',', $GEOdata); if ($GEOtype == "country") { $radius = ',479km'; } else { $radius = ',35mi'; } $GEOdatax = $GEOdatax . $radius; } } return $GEOdatax; }
/** * Performs a request using the TwitterOAuth library * @see https://twitteroauth.com/ * @param $action - what to retrieve from the Twitter REST API (e.g. trends/place ) * @param $params - parameters to be passed during the Twitter API request */ function perform_request($action, $params){ $connection = new TwitterOAuth(TwitterConfig::$consumerKey, TwitterConfig::$consumerSecret, TwitterConfig::$accessToken, TwitterConfig::$accessTokenSecret); $response = $connection->get($action, $params); echo json_encode($response); }
public function getPosts() { //接続情報 $connection = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $this->accessToken, $this->accessTokenSecret); $content = $connection->get("search/tweets", ["geocode" => $this->location, "result_type" => "recent"]); return $content; }
public function actionTweets() { $postData = Yii::$app->getRequest()->getBodyParams(); if (isset($postData['latitude']) && $postData['latitude'] && isset($postData['longitude']) && $postData['longitude']) { $data = Yii::$app->cache->get($postData['city']); if ($data === false) { // $data is expired or is not found in the cache $geocode = $postData['latitude'] . ',' . $postData['longitude'] . ',' . self::SEARCH_RADIUS; $connection = new TwitterOAuth('wT8o4IrBGCCNcnHxZfobEvHVV', 'eG3GQ7nqMXzO14IK7whGd1SyQmWqrKKRfgJJXmeqp910ryA3NV', '2376724225-0m1tu3Q8ru20mTyA0zjxGFKxRBEQkBTaTCAszQl', 'FEuuyd15giBingpwBgpIlQ0T419cUKcAA4kPJF6QLmiNb'); $tweets = $connection->get("search/tweets", array("geocode" => $geocode)); $result = []; foreach ($tweets->statuses as $tweet) { //check tweet with geo exist if (isset($tweet->geo) && is_array($tweet->geo->coordinates) && count($tweet->geo->coordinates) > 0) { $result[] = array('desc' => $tweet->text, 'avatar' => $tweet->user->profile_image_url, 'created_at' => $tweet->created_at, 'lat' => $tweet->geo->coordinates[0], 'long' => $tweet->geo->coordinates[1]); } } $this->insertTweets($postData['city'], $result); Yii::$app->cache->set($postData['city'], $result, self::CACHE_TIME); return ['success' => true, 'result' => $result]; } else { return ['success' => true, 'result' => $data]; } } return ['success' => false, 'result' => []]; }
private function _callbackFlow() { // 不正認証防止用に認証リクエスト用トークンをチェック if ($_GET['oauth_token'] !== $_SESSION['tmp_twitter_oauth_token']) { echo "Invalid Token!"; exit; } // twitterのユーザー情報の取得 $conn = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $_SESSION['tmp_twitter_oauth_token'], $_SESSION['tmp_twitter_oauth_token_secret']); $tokens = $conn->oauth('oauth/access_token', ['oauth_verifier' => $_GET['oauth_verifier']]); //取得したtwitterユーザー情報をDBに登録もしくは更新 $user = new \App\Model\User(); if ($user->existsTwitterUser($tokens['user_id'])) { if (!$user->updateTwitterUser($tokens)) { echo "update error!"; exit; } } else { if (!$user->createTwitterUser($tokens)) { echo "create error!"; exit; } } //ログイン処理 session_regenerate_id(true); $_SESSION['user'] = $user->findTwitterUser(['tw_user_id' => $tokens['user_id']]); //認証リクエスト用トークンはもう使わないので消す unset($_SESSION['tmp_twitter_oauth_token']); unset($_SESSION['tmp_twitter_oauth_token_secret']); header('Location: ' . SITE_URL); exit; }
function GetFollowersIds() { /*session_start(); $connection = new TwitterOAuth("CONSUMER_KEY", "CONSUMER_SECRET"); $_SESSION['oauth_token'] = $token = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; $url = $connection->getAuthorizeURL($token); $connection = new TwitterOAuth("CONSUMER_KEY", "CONSUMER_SECRET", $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); $_SESSION['access_token'] = $access_token; unset($_SESSION['oauth_token']); unset($_SESSION['oauth_token_secret']); $connection = new TwitterOAuth('CONSUMER_KEY', 'CONSUMER_SECRET', $access_token['oauth_token'], $access_token['oauth_token_secret']); $content = $connection->get('followers/ids'); var_dump($content);*/ $connection = new TwitterOAuth("CONSUMER_KEY", "CONSUMER_SECRET"); $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => 'CONSUMER_KEY')); var_dump($access_token); }
public static function setLogin($token, $isadmin = false, $db) { $_auth['tw_token'] = $token; $twitter = new TwitterOAuth(tw_consumer_key, tw_consumer_secret, $token['oauth_token'], $token['oauth_token_secret']); $response = $twitter->get('account/verify_credentials'); $user = array('id' => $response->id, 'name' => $response->name, 'screen_name' => $response->screen_name, 'location' => $response->location, 'time_zone' => $response->time_zone, 'verified' => $response->verified, 'profile_image_url' => $response->profile_image_url, 'lang' => $response->lang); $_auth['user'] = $user; $_auth['isadmin'] = $user['id'] === 83455478; // $_auth['twitter']=$twitter; $sth = $db->prepare('INSERT INTO login ( twitter_id, twitter_name, twitter_screen_name, twitter_location, twitter_time_zone, twitter_lang ) VALUES ( :twitter_id, :twitter_name, :twitter_screen_name, :twitter_location, :twitter_time_zone, :twitter_lang )'); $sth->execute(array(':twitter_id' => $user['id'], ':twitter_name' => $user['name'], ':twitter_screen_name' => $user['screen_name'], ':twitter_location' => $user['location'], ':twitter_time_zone' => $user['time_zone'], ':twitter_lang' => $user['lang'])); $_auth['login_id'] = $db->lastInsertId(); session::set('auth', $_auth); }
/** * @return void * @throws \Exception */ public function execute() { $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; $data = $this->getRequest()->getParams(); /* Get temporary credentials from session. */ $request_token = []; $request_token['oauth_token'] = $this->scopeConfig->getValue('sama_twitterfeed/oauth/token', $storeScope); $request_token['oauth_token_secret'] = $this->scopeConfig->getValue('sama_twitterfeed/oauth/token_secret', $storeScope); /* If denied, bail. */ if (isset($data['denied'])) { throw new Exception("Twitter denied permission"); } /* If the oauth_token is not what we expect, bail. */ if (isset($data['oauth_token']) && $request_token['oauth_token'] !== $data['oauth_token']) { throw new Exception("Unexpected Oauth token"); } /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */ $connection = new TwitterOAuth($this->_oAuthkey, $this->_oAuthsecret, $request_token['oauth_token'], $request_token['oauth_token_secret']); /* Request access tokens from twitter */ $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $data['oauth_verifier'])); /* If HTTP response is 200 continue otherwise send to connect page to retry */ if (200 == $connection->getLastHttpCode()) { $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/access_token', $access_token); $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/token_secret', null); $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/token', null); } else { throw new Exception("Twitter Oauth API status code: {$connection->getLastHttpCode()}"); } return; }
public function Oauth() { $oauth = new TwitterOAuth($this->key, $this->secret); $accessToken = $oauth->oauth2('oauth2/token', ['grant_type' => 'client_credentials']); $twitter = new TwitterOAuth($this->key, $this->secret, null, $accessToken->access_token); return $twitter; }
/** * Setup TwitterOAuth * * $twitterAuthConf must contain * - consumer_key * - consumer_secret * - oauth_access_token * - oauth_access_token_secret * * @param array $twitterAuthConf * @return $this */ public function setupTwitter(array $twitterAuthConf) { $twitterAuthConf += ['consumer_key' => null, 'consumer_secret' => null, 'oauth_access_token' => null, 'oauth_access_token_secret' => null]; $this->twitter = new TwitterOAuth($twitterAuthConf['consumer_key'], $twitterAuthConf['consumer_secret'], $twitterAuthConf['oauth_access_token'], $twitterAuthConf['oauth_access_token_secret']); $this->twitter->setDecodeJsonAsArray(true); return $this; }
public function create() { DB::transaction(function () { $twitterClient = new TwitterOAuth(Config::get('services.twitter.consumerKey'), Config::get('services.twitter.consumerSecret'), Config::get('services.twitter.accessToken'), Config::get('services.twitter.accessSecret')); // Fetch the tweet information from Twitter, if a tweet id was passed through (it is possible the tweet was created manually without an id) if (array_key_exists('tweet_id', $this->input)) { $tweet = $twitterClient->get('statuses/show', ['id' => $this->input['tweet_id']]); $tweetOwner = $tweet->user; $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $tweet->text, 'tweet_id' => $tweet->id, 'tweet_parent_id' => $tweet->in_reply_to_status_id, 'size' => strlen($tweet->text), 'title' => $tweet->text, 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $tweet->text), 'originated_at' => Carbon::createFromFormat('D M d H:i:s P Y', $tweet->created_at)->toDateTimeString(), 'status' => ObjectPublicationStatus::QueuedStatus]); } else { $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $this->input['tweet_text'], 'size' => strlen($this->input['tweet_text']), 'title' => $this->input['tweet_text'], 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $this->input['tweet_text']), 'originated_at' => $this->input['originated_at'], 'status' => ObjectPublicationStatus::QueuedStatus]); } try { if (!isset($tweetOwner)) { $tweetOwner = $twitterClient->get('users/show', ['screen_name' => $this->input['tweet_screen_name']]); } $tweeter = Tweeter::byScreenName($tweetOwner->screen_name)->firstOrFail(); } catch (ModelNotFoundException $e) { $tweeter = Tweeter::create(['screen_name' => $tweetOwner->screen_name, 'user_name' => $tweetOwner->name, 'description' => $tweetOwner->description]); $tweeter->saveProfilePicture(); } $this->object->tweeter()->associate($tweeter); $this->createMissionRelation(); $this->createTagRelations(); $this->object->push(); }); return $this->object; }
/** * {@inheritdoc} */ public function checkCredentials() { $application = $this->twitterOauth->get('account/verify_credentials'); if (isset($application->errors)) { throw new BadAuthenticationException(sprintf('An error occurred during the authentication : %s', implode(', ', $this->parseErrors($application->errors)))); } return true; }
public function getAuthorizationUrl(array $options = []) { $connection = new TwitterOAuth($this->clientId, $this->clientSecret); $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => $this->redirectUri)); $options["session"]->write('twitter.request_token', $request_token); $url = $connection->url('oauth/authenticate', array('oauth_token' => $request_token['oauth_token'])); return $url; }
/** * @param Article $article * @param string $header */ public function provide(Article $article, $header = "") { $this->twitter->post("statuses/update", array("status" => "{$header} {$article->getTitle()} >> http://matomepp.net/p/{$article->getArticleId()}")); if ($this->twitter->getLastHttpCode() != 200) { throw new \RuntimeException(json_encode($this->twitter->getLastBody())); } $this->storeTweets($article); }
public function fetch($limit = FALSE) { // XXX: Store state in database config for now $config = Kohana::$config; $this->_initialize($config); //Check if data provider is available $providers_available = $config->load('features.data-providers'); if (!$providers_available['twitter']) { Kohana::$log->add(Log::WARNING, 'The twitter data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.'); return 0; } // check if we have reached our rate limit if (!$this->_can_make_request()) { Kohana::$log->add(Log::WARNING, 'You have reached your rate limit for this window'); return 0; } $options = $this->options(); // Check we have the required config if (!isset($options['consumer_key']) || !isset($options['consumer_secret']) || !isset($options['oauth_access_token']) || !isset($options['oauth_access_token_secret']) || !isset($options['twitter_search_terms'])) { Kohana::$log->add(Log::WARNING, 'Could not fetch messages from twitter, incomplete config'); return 0; } $connection = new TwitterOAuth($options['consumer_key'], $options['consumer_secret'], $options['oauth_access_token'], $options['oauth_access_token_secret']); // Increase curl timeout values $connection->setTimeouts(100, 150); $count = 0; try { $results = $connection->get("search/tweets", ["q" => $this->_construct_get_query($options['twitter_search_terms']), "since_id" => $this->since_id, "count" => $limit, "result_type" => 'recent']); if (!$results->statuses) { return 0; } $statuses = $results->statuses; // Store the highest id $this->since_id = $statuses[0]->id; foreach ($statuses as $status) { $id = $status->id; $user = $status->user; $screen_name = $user->screen_name; $text = $status->text; // Try to connect with some service for structure data $payload = array('message' => $text); $twtan = new TwitterAnalyzer(); $result_json = $twtan->analyze($payload); $text = $text . "\n\n" . $result_json; // @todo Check for similar messages in the database before saving $this->receive(Message_Type::TWITTER, $screen_name, $text, $to = NULL, $title = NULL, $id); $count++; } $this->request_count++; //Increment for successful request $this->_update($config); } catch (TwitterOAuthException $toe) { Kohana::$log->add(Log::ERROR, $toe->getMessage()); } catch (Exception $e) { Kohana::$log->add(Log::ERROR, $e->getMessage()); } return $count; }
public function __construct($apiKey, $apiKeySecret) { $this->apiKey = $apiKey; $this->apiKeySecret = $apiKeySecret; $oauth = new TwitterOAuth($this->apiKey, $this->apiKeySecret); $accessToken = $oauth->oauth2('oauth2/token', ['grant_type' => 'client_credentials']); $this->access_token = $accessToken->access_token; $this->twitter = new TwitterOAuth($this->apiKey, $this->apiKeySecret, null, $this->access_token); }
public function getTweets() { $toa = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $this->accessToken, $this->accessTokenSecret); $toa->setTimeouts(10, 15); $hashtag = '#4LTrophy'; $query = ['q' => $hashtag]; $results = $toa->get('search/tweets', $query); return $results->statuses; }
public function getUserInformation($user_oauth_token, $user_oauth_verifier) { $connection = new TwitterOAuth($this->consumer_key, $this->consumer_secret, $user_oauth_token, $_SESSION['oauth_token_secret']); $access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $user_oauth_verifier]); $connection2 = new TwitterOAuth($this->consumer_key, $this->consumer_secret, $access_token['oauth_token'], $access_token['oauth_token_secret']); $user = $connection2->get("account/verify_credentials"); $this->response['data'] = ['imagePath' => str_replace('_normal', '', $user->profile_image_url), 'imageThumb' => $user->profile_image_url, 'twitterId' => $user->id, 'name' => $user->name]; return $this->response; }
function GenerateLoginLink() { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK)); $_SESSION['oauth_token'] = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token'])); return $url; }
public function getAccessToken() { if (!isset($_SESSION['access_token']) && !isset($_SESSION['access_token_secret'])) { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_COOKIE['oauth_token'], $_COOKIE['oauth_token_secret']); $access_token = $connection->oauth('oauth/access_token', array('oauth_verifier' => $_GET['oauth_verifier'])); $_SESSION['access_token'] = $access_token['oauth_token']; $_SESSION['access_token_secret'] = $access_token['oauth_token_secret']; } }
public function twitter() { $connection = new TwitterOAuth(Config::get('twitter.appid'), Config::get('twitter.secret')); $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => Config::get('twitter.callback'))); $_SESSION['login_type'] = "twitter"; $_SESSION['oauth_token'] = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token'])); return redirect($url); }
public function postStatus($status) { try { $connection = new TwitterOAuth($this->_consumerKey, $this->_consumerSecret, $this->_oauthToken, $this->_oauthSecret); $content = $connection->get('account/verify_credentials'); $connection->post('statuses/update', array('status' => $status)); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } }
public function search(Request $request) { //post ile gönderilen datalarımız.. $data = $request->all(); //twitter ayarlarımız acces_token,access_token_Secret vs... $twitter_config = Config::get('twitter'); $connection = new TwitterOAuth($twitter_config['consumer_key'], $twitter_config['consumer_secret'], $twitter_config['access_token'], $twitter_config['access_token_secret']); $statuses = $connection->get("search/tweets", array("q" => $data['search_word'], "count" => $data['max_word_count'])); return view('twitter_listele', ["statuses" => $statuses]); }
public function getFeedUncached() { // NOTE: Twitter doesn't implement OAuth 2 so we can't use https://github.com/thephpleague/oauth2-client $connection = new TwitterOAuth($this->ConsumerKey, $this->ConsumerSecret, $this->AccessToken, $this->AccessTokenSecret); $result = $connection->get('statuses/user_timeline', ['count' => 25, 'exclude_replies' => true]); if (isset($result->error)) { user_error($result->error, E_USER_WARNING); } return $result; }
function getTweets($querySTring) { $oauth_token = "4530140774-8eJh3ti4Px4aa76jb4YNhrRdZ5vyxGAKGUMUZ7S"; $oauth_token_secret = "XxsU4wuZbYYjDaXWgShbT9TWyVXiEVqUmQqVZ9e68KgeJ"; // $connection = getConnectionWithAccessToken($oauth_token, $oauth_token_secret); $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret); $statuses = $connection->get("search/tweets", array("q" => $querySTring)); //var_dump($statuses); $tweets = $statuses->statuses; return $tweets; }
public function getTweets() { if (time() - filemtime($this->cache) > 60) { $connection = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $this->accessToken, $this->accessTokenSecret); $tweets = $connection->get("statuses/user_timeline", ['screen_name' => '3WAcademy', 'exclude_replies' => true, 'count' => 5]); file_put_contents($this->cache, serialize($tweets)); } else { $tweets = unserialize(file_get_contents($this->cache)); } return $tweets; }
public function saveProfilePicture() { $twitterClient = new TwitterOAuth(Config::get('services.twitter.consumerKey'), Config::get('services.twitter.consumerSecret'), Config::get('services.twitter.accessToken'), Config::get('services.twitter.accessSecret')); // Fetch the URL of the user's profile picture $user = $twitterClient->get('users/show', ['screen_name' => $this->screen_name]); $profilePictureUrl = preg_replace("/_normal/", "", $user->profile_image_url); // Save it locally $profilePicture = file_get_contents($profilePictureUrl); create_if_does_not_exist(public_path('media/twitterprofiles')); file_put_contents(public_path('media/twitterprofiles/' . $this->screen_name . '.png'), $profilePicture); }