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; }
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); }
/** * {@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; }
/** * Show the application dashboard. * * @return Response */ public function index() { $access_token = getenv('TWITTER_ACCESS_TOKEN'); $access_token_secret = getenv('TWITTER_ACCESS_TOKEN_SECRET'); $consumer_key = getenv('TWITTER_CONSUMER_KEY'); $consumer_secret = getenv('TWITTER_CONSUMER_SECRET'); $connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret); $content = $connection->get("account/verify_credentials"); $statuses = $connection->get("statuses/home_timeline", array("count" => 25, "exclude_replies" => true)); error_log(print_r($statuses, true)); return view('mytweets', ['mytweets' => $statuses]); }
function search($string, $count, $type) { $access_token = "3227234898-oMKzM9SSY9aE5I4viIisGZ58mQJceIPn6KhCiS9"; $access_token_secret = "xHN3fYrkGAiNgSowvxigh1mMLXfegDtozP04f0s1ODRT1"; $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); $content = $connection->get("account/verify_credentials"); // var_dump($content); $statuses = $connection->get("search/tweets", array("lang" => "pt", "q" => $string, "count" => "20", "result_type" => $type)); // var_dump($statuses); // echo '<pre>'; print_r($statuses); echo '</pre>'; return $statuses; }
/** * @return TwitterOAuth */ protected function getConnection() { if ($this->connection === null) { $config = Di::getDefault()->getConfig()->get('twitter'); $this->connection = new TwitterOAuth($config['apiKey'], $config['apiSecret'], $config['accessToken'], $config['accessTokenSecret']); $content = $this->connection->get("account/verify_credentials"); if (isset($content->errors)) { var_dump($content->errors); die; } } return $this->connection; }
/** * return the (xà last tweet(s) for an screenname * * @param $username * @param $count * @param bool $replies * @param bool $rts * @return array */ public function getLastTweets($username, $count, $replies = false, $rts = false) { $tweets = $this->twitter->get('statuses/user_timeline', ['screen_name' => $username, 'exclude_replies' => !$replies, 'include_rts' => $rts, 'count' => $count]); $response = []; foreach ($tweets as $tweet) { $t = new Tweet(); $t->setText($tweet->text); $t->setSource($tweet->source); $t->setName($tweet->user->name); $t->setScreen($tweet->user->screen_name); $t->setDate($tweet->created_at); $response[] = $t; } return $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 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); }
/** * 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 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; }
public function testLastResult() { $this->twitter->get('search/tweets', array('q' => 'twitter')); $this->assertEquals('search/tweets', $this->twitter->getLastApiPath()); $this->assertEquals(200, $this->twitter->getLastHttpCode()); $this->assertObjectHasAttribute('statuses', $this->twitter->getLastBody()); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { // get all places from db $places = Place::model()->findAll(); // *** twitter api *** // //twitter authentication $connection = new TwitterOAuth("8gpWBVBSfGB2clOm8thLz29yu", "KkSJTv5chO4e6AzGsOkctKnk8nnFjdHzXzISDLM48AZ91gneGG", "3299182320-gipHvZakrdUnQIzfLVP4D5i4uP34vxfqSabxHny", "7D93mzbvVxwujnH20vYbuCPM8LRpZ1vfhCq4LEW5bwGrA"); $content = $connection->get("account/verify_credentials"); // search tweets $tweets = $connection->get("search/tweets", array("q" => "chiangmai")); // *** end twitter api *** // // weather api $weather = json_decode(file_get_contents("http://api.openweathermap.org/data/2.5/weather?q=chiangmai&units=metric")); // render index page and pass places, tweets, and weather $this->render('index', array('places' => $places, 'tweets' => $tweets, 'weather' => $weather)); }
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' => []]; }
/** * get user's twitter feed * * @return array|bool */ public function getFeed() { $oFeed = $this->_oTwitterOAth->get("statuses/home_timeline", ["count" => 25, "exclude_replies" => true]); if ($this->_oTwitterOAth->getLastHttpCode() === 200) { return $oFeed; } return false; }
public function loginTwitter($data) { if (!Session::has('access_token')) { $connection = new TwitterOAuth(config('socialpack.composer_key'), config('socialpack.composer_secret')); $callback_url = url('/') . '/callbackTwitter'; $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => (string) $callback_url)); Session::put('oauth_token', $request_token['oauth_token']); Session::put('oauth_token_secret', $request_token['oauth_token_secret']); $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token'])); return redirect()->away($url); } else { $access_token = Session::get('access_token'); $connection = new TwitterOAuth(config('socialpack.composer_key'), config('socialpack.composer_secret'), $access_token['oauth_token'], $access_token['oauth_token_secret']); if (isset($data) && !empty($data)) { if (isset($data['profile']) && !empty($data['profile'])) { if ($data['profile'] == "yes") { // getting basic user info $user = $connection->get("account/verify_credentials"); return $user; } } if (isset($data['post_tweet']) && !empty($data['post_tweet'])) { if ($data['post_tweet']["show"] == "yes") { // posting tweet on user profile $post = $connection->post('statuses/update', array('status' => $data['post_tweet']["message"])); return $post; } } if (isset($data['recent_tweets']) && !empty($data['recent_tweets'])) { if ($data['recent_tweets']["show"] == "yes") { // getting recent tweeets by user 'snowden' on twitter $tweets = $connection->get('statuses/user_timeline', ['count' => 200, 'exclude_replies' => true, 'screen_name' => 'snowden', 'include_rts' => false]); $totalTweets[] = $tweets; $page = 0; for ($count = 200; $count < 500; $count += 200) { $max = count($totalTweets[$page]) - 1; $tweets = $connection->get('statuses/user_timeline', ['count' => 200, 'exclude_replies' => true, 'max_id' => $totalTweets[$page][$max]->id_str, 'screen_name' => 'snowden', 'include_rts' => false]); $totalTweets[] = $tweets; $page += 1; } return $totalTweets; } } } } }
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 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; }
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 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 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; }
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 signedIn() { if (isset($_SESSION['twitter_access_token'])) { $access_token = $_SESSION['twitter_access_token']; $connection = new TwitterOAuth(self::CONSUMER_KEY, self::CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $user = $connection->get('account/verify_credentials'); return $user; } return false; }
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 twittersearch($query) { $consumer = "3Hsr7qk9HEYseF9bpJA07Go6H"; $consumersecret = "q1TjkWCHcPKrJn0YCmtKMwIHaXURI7ip3z5eDxDd4G0GxLsUOi"; $accesstoken = "3803581341-FAlmx3CbE2amgcMyD2AkGYuLdRa7kZ3QcDSxj5a"; $accesstokensecret = "1JtROKIjMaIhP6IJGMPGbTyRTF9WMyq1RGclpdvcKzZWD"; $twitter = new TwitterOAuth($consumer, $consumersecret, $accesstoken, $accesstokensecret); $url = "search/tweets"; $tweets = $twitter->get($url, array('q' => $query, 'result_type' => 'recent', 'count' => '200')); return $tweets; }
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 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); }
public function getTweets() { // 1 minute if (!file_exists($this->cache) || time() - filemtime($this->cache) > 60) { $connection = new TwitterOAuth($this->consumer_key, $this->consumer_secret, $this->access_token, $this->access_token_secret); $tweets = $connection->get("statuses/user_timeline", ['screen_name' => 'unpetitlu', 'exclude_replies' => true, 'count' => 10]); file_put_contents($this->cache, serialize($tweets)); } else { $tweets = unserialize(file_get_contents($this->cache)); } return $tweets; }
function mp_get_new_twitter_statuses($count = 5) { // These Values Are Required $consumer_key = ''; $consumer_secret = ''; $access_token = ''; $access_token_secret = ''; $connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret); $statuses = $connection->get("statuses/user_timeline", ["count" => $count, "exclude_replies" => true]); mp_update_twitter_cache($statuses); return $statuses; }
public static function Connection() { if (self::$connection) { return self::$connection; } $config = self::config(); $consumer_key = $config->consumer_key; $consumer_secret = $config->consumer_secret; $oauth_token = $config->oauth_token; $oauth_token_secret = $config->oauth_token_secret; if (empty($consumer_key) || empty($consumer_secret) || empty($oauth_token) || empty($oauth_token_secret)) { throw new Exception(__METHOD__ . '(): Twitter credentials do not exist in the configuration.'); } self::$connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret); self::$connection->setTimeouts(30, 30); //Test the connection $response = self::$connection->get('account/verify_credentials'); if (self::Error()) { throw new Exception(__METHOD__ . '(): Connection failed. ' . self::ErrorMessage($response)); } return self::$connection; }