public function sendMessage($message) { try { Twitter::postTweet(array('status' => substr($message, 0, 140), 'format' => 'json')); } catch (Exception $e) { var_dump($e->getMessage()); } }
public function loadUserByUsername($username) { $user = $this->findUserByTwitterId($username); if (!empty($user)) { return $user; } $this->twitter_oauth->setOAuthToken($this->session->get('access_token'), $this->session->get('access_token_secret')); try { $info = $this->twitter_oauth->get('account/verify_credentials'); } catch (Exception $e) { $info = null; } if (!empty($info)) { if (empty($user)) { $user = $this->userManager->createUser(); $user->setEnabled(true); $user->setPassword(''); } $user->setTwitterData($info); $this->userManager->updateUser($user); } if (empty($user)) { throw new UsernameNotFoundException('The user is not authenticated on twitter'); } return $user; }
public function twitterUserTimeLine() { $twit = new Twitter(); $user = $this->params[0]; $count = (int) $this->params[1]; return $twit->getUserTimeLine($user, $count); }
public function action_results() { $username = Input::get('username'); $username = urlencode($username); $twitter = new Twitter(); $twitter_results = array('username' => $username, 'results' => $twitter->getTweetsFromXML($username)); return View::make('home.results', $twitter_results); }
public static function twitter($title) { $twitter = new Twitter(); if ($twitter->tweet($title)) { return true; } return false; }
/** * Twitter API instance loaded with token/secret for this user. */ function twitter() { if (!$this->twitter_oauth_token) { return NULL; } $twitter = new Twitter(); $twitter->setToken($this->twitter_oauth_token, $this->twitter_oauth_token_secret); return $twitter; }
/** Initiate request to create a twitter access token. This can only be * done when logged into twitter * and also as an admin * @access public * @return void * @throws Pas_Yql_Exception */ public function twitteraccessAction() { $twitter = new Twitter(); $twitter->access(); if (isset($twitter)) { $this->getFlash()->addMessage('Token created'); $this->redirect('admin/oauth/'); } else { throw new Pas_Yql_Exception('Token creation failed', 500); } }
function post_to_twitter($message) { # These keys are for the @playbitfighter twitter account. # Log in and go to https://apps.twitter.com/ to manage them $consumerKey = "REPLACEME"; $consumerSecret = "REPLACEME"; $accessToken = "REPLACEME"; $accessTokenSecret = "REPLACEME"; $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); $twitter->send($message); }
function __construct($username = '******') { // prepare the client; $twitterClient = new \Twitter(getenv('TWITTER_CONSUMER_KEY'), getenv('TWITTER_CONSUMER_SECRET'), getenv('TWITTER_ACCESS_TOKEN'), getenv('TWITTER_ACCESS_TOKEN_SECRET')); // populate info try { $this->info = $twitterClient->request('users/show', 'GET', ['screen_name' => $username]); } catch (Exception $e) { return "Exception: {$e}"; } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $t = new Twitter(sfConfig::get('twitter_username'), sfConfig::get('twitter_password')); $needs = NeedPeer::retrieveAllNeeds($connection); foreach ($needs as $need) { $message = 'People, @' . $need->getAuthor() . ' needs ' . $need->getDescription() . ' ' . $need->getTimeframe() . ', please help!'; $t->updateStatus($message); } }
protected function _checkForTwitterUpdates() { $cache_time = 300; $cache_filepath = DIR_CACHE . 'twitter-' . APIA_TWITTER_USER . '-pull-ts.cache'; $last_pull_time = (int) @file_get_contents($cache_filepath); $now_time = time(); if ($now_time - $last_pull_time > $cache_time) { /* get the last entered twitter entry */ $query = 'SELECT UNIX_TIMESTAMP(creativeartsguide.feed.timestamp) AS time FROM creativeartsguide.feed WHERE creativeartsguide.feed.type=3 ORDER BY creativeartsguide.feed.timestamp DESC LIMIT 1'; $DbStmt = $this->getDatabase()->prepare($query)->execute(); $DbStmt->first(); $last_item_pulled = $DbStmt->time ? $DbStmt->time : 00; $last_item_pulled = (int) $last_item_pulled + 1; /* use Twitter API class to get XML return for request */ $Twitter = new Twitter(APIA_TWITTER_USER, APIA_TWITTER_PASS); $twitter_xml = $Twitter->getUserTimeline(); $twitter_status = new SimpleXMLElement($twitter_xml); $i = 0; /* loop through each returned tweet (or status) */ foreach ($twitter_status->status as $s) { /* get the information we need from the object */ $t_time = (int) strtotime($s->created_at); $t_fav = (string) $s->favorited; $t_text = (string) $this->_addTwitterLinks($s->text); /* skip any posts that are already in the database */ if ($last_item_pulled > $t_time) { continue; } /* skip any posts that are not favorited */ if ((string) $s->favorited != 'true') { continue; } /* insert new twitter post id and timestamp */ $query = 'INSERT INTO :T1 SET :T1.type=:A1, :T1.timestamp=FROM_UNIXTIME(:A2)'; $DbStmt = $this->getDatabase()->prepare($query, array('creativeartsguide.feed'))->execute(array(3, $t_time)); $insert_id = $DbStmt->insertId(); /* insert new twitter post content */ $query = 'INSERT INTO :T1 SET :T1.feed_id=:A1, :T1.post=:A2'; $DbStmt = $this->getDatabase()->prepare($query, array('creativeartsguide.feed_post'))->execute(array($insert_id, $t_text)); } /* cache this data... */ $fhandle = fopen($cache_filepath, 'wb'); fwrite($fhandle, time()); fclose($fhandle); } }
/** * Figure out identity of the Twitterrer and log them in */ protected function login_with_oauth($token, $secret) { $twitter = new Twitter(); $twitter->setToken($token, $secret); $creds = $twitter->get('/account/verify_credentials.json'); $user = $twitter->user_from_response($creds); $user->twitter_oauth_token = $token; $user->twitter_oauth_token_secret = $secret; $user->save(); $this->login_user($user); // return $this->return_to(); // since return_to saves any stupid URL, this causes redirect loops return array('redirect' => '/'); }
public function postTweet() { $veri = Input::all(); if (empty($veri['consumer_key']) && empty($veri['consumer_secret']) && empty($veri['access_token']) && empty($veri['access_token_secret'])) { $twit = new Twitter(); $arama_sonuc = $twit->SearchTweet($twit->permalink(trim($veri['search_word'])), $veri['max_word_count']); return View::make('tweet_listele', array("arama_sonuc" => $arama_sonuc)); } else { $veri = new Twitter(); $veri->connection($veri['consumer_key'], $veri['consumer_secret'], $veri['access_token'], $veri['access_token_secret']); $arama_sonuc = $twit->SearchTweet($twit->permalink(trim($veri['search_word'])), $veri['max_word_count']); return View::make('tweet_listele', array("arama_sonuc" => $arama_sonuc)); } }
function broadcast($first, $last, $city = "", $gender = "", $age = "", $info = "", $photo = "", $lang = "en", $status = "missing") { global $twitter_debug; if (strtolower($lang) == "ht") { $twitter = new Twitter("haitimissingkr", "zWqOEOrC0RkPTwVOnJ88"); } else { $twitter = new Twitter("haitimissing", "zWqOEOrC0RkPTwVOnJ88"); } // English Twitter Feed $update = ""; $update .= ucwords(strtolower($last)); $update .= " "; $update .= ucwords(strtolower($first)); if (strtoupper($gender) == "M" || strtoupper($gender) == "F") { $update .= ", " . strtoupper($gender); } if ($age != "") { $update .= ", " . $age; } if ($city != "") { $update .= ", " . ucwords(strtolower($city)); } if (strtolower($status) != "missing") { $update .= ", " . ucwords($status); } if ($info != "") { $info = compress_URL($info); if (strtolower($lang) == "ht") { $update .= ", info: " . $info; } else { $update .= ", info: " . $info; } } if ($photo != "") { $photo = compress_URL($photo); if (strtolower($lang) == "ht") { $update .= ", photo: " . $photo; } else { $update .= ", photo: " . $photo; } } $update .= " #haitimissing"; if ($twitter_debug) { echo "Posted: " . $update . " in " . $lang; } else { $twitter->updateStatus($update); } }
public static function twSlider($app, $data) { preg_match_all("/\\[\\[twitter\\]\\]/", $data, $res); $cfg = unserialize(TWITTER_CONFIG); try { $twitter = new Twitter($cfg['API_key'], $cfg['API_secret'], $cfg['token'], $cfg['secret']); $statuses = $twitter->load(Twitter::ME); } catch (Exception $e) { $statuses = null; } foreach ($res[0] as $tw) { $tw = $app['twig']->render('twitter.twig', array('twitter' => $statuses)); $data = str_replace("[[twitter]]", $tw, $data); } return $data; }
/** * Gets the path * * @return string */ public static function getPath() { if (!self::$_path) { self::$_path = dirname(__FILE__); } return self::$_path; }
public static function update_status($str) { $bitly = new Url_Shortner(array("login" => ORM::factory('setting', 'bitly_login')->value, "key" => ORM::factory('setting', 'bitly_api')->value)); $str = $bitly->string_shorten($str); $twitter = Twitter::instance(ORM::factory('setting', 'twitter_username')->value, ORM::factory('setting', 'twitter_password')->value); $twitter->update_status($str); }
public function twitterCallback() { if (Session::has('oauth_request_token')) { $request_token = array('token' => Session::get('oauth_request_token'), 'secret' => Session::get('oauth_request_token_secret')); Twitter::set_new_config($request_token); $oauth_verifier = FALSE; if (Input::has('oauth_verifier')) { $oauth_verifier = Input::get('oauth_verifier'); } // getAccessToken() will reset the token for you $token = Twitter::getAccessToken($oauth_verifier); if (!isset($token['oauth_token_secret'])) { return Redirect::to('/')->with('flash_error', 'We could not log you in on Twitter.'); } $credentials = Twitter::query('account/verify_credentials'); if (is_object($credentials) && !isset($credentials->error)) { // $credentials contains the Twitter user object with all the info about the user. // Add here your own user logic, store profiles, create new users on your tables...you name it! // Typically you'll want to store at least, user id, name and access tokens // if you want to be able to call the API on behalf of your users. // This is also the moment to log in your users if you're using Laravel's Auth class // Auth::login($user) should do the trick. return Redirect::to('/')->with('flash_notice', "Congrats! You've successfully signed in!"); } return Redirect::to('/')->with('flash_error', 'Crab! Something went wrong while signing you up!'); } }
public static function instance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
static function get_list_of_friends($twitterUserID) { if ($twitterUserID) { $url = "http://api.twitter.com/1/friends/ids.json?user_id={$twitterUserID}"; } else { throw new Exception("No id is being passed to the twitter api."); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $curlout = curl_exec($ch); curl_close($ch); $response = json_decode($curlout, true); $ids = ""; $count = 0; $array = array(); foreach ($response["ids"] as $friend) { $ids .= "{$friend},"; $count++; if ($count == 100) { $array = array_merge($array, Twitter::get_list_of_fifty_friends($ids)); $count = 0; $ids = ""; } } if ($count > 0) { $array = array_merge($array, Twitter::get_list_of_fifty_friends($ids)); } return $array; }
function __construct($status) { $this->status = $status; $this->readable = \Twitter::clickable($status); $this->link = "https://twitter.com/{$status->user->screen_name}/status/{$status->id_str}"; $this->mobileLink = "https://mobile.twitter.com/{$status->user->screen_name}/status/{$status->id_str}"; }
public function __construct() { if (Agent::isMobile()) { $this->_vista = 'mobile'; } else { $this->_vista = 'index'; } $this->_imagesInstagram = array(); $this->_imagesTwitter = array(); $instagram = new instagram(array('apiKey' => '09fd60952ea742d5abb761b6c6a137aa', 'apiSecret' => 'ee25063e91e74d6c9f257be054a44ec3', 'apiCallback' => 'http://viernesdezapatillas.pe/')); $tagInstagram = 'viernesdezapatillas'; $numphotosInstagram = 15; $media = $instagram->getTagMedia($tagInstagram, $auth = false, array('count' => $numphotosInstagram)); $response = json_decode(json_encode($media)); foreach ($response->data as $data) { $this->_imagesInstagram[] = $data->images->thumbnail->url; } $max_id = 0; $totalTweets = 15; $responset = Twitter::getSearch(array('q' => '#viernesdezapatillas since:2015-07-01 filter:images', 'count' => $totalTweets, 'max_id' => $max_id, 'since_id' => 0)); foreach ($responset->statuses as $tweet) { foreach ($tweet->entities->media as $url) { $this->_imagesTwitter[] = $url->media_url; // . ':thumb'; } } }
/** * Test for get_authenticate_url() */ public function test_get_authenticate_url() { $t = Twitter::forge(); $oauth_token = 'xxx'; $actual = $t->get_authenticate_url($oauth_token); $expected = 'https://api.twitter.com/oauth/authenticate?oauth_token=xxx'; $this->assertEquals($expected, $actual); }
public function activityUpdatesBySubject($dryrun = false) { echo "<h3>Running Activity Tweet Update</h3><i>Date Started: " . date('r') . "</i>" . BR . BR; if ($dryrun == "true") { echo "<pre>RUNNING IN DRY-RUN MODE - NO ACTUAL TWEETS WILL BE SENT!!! Remove /true in the URL to run properly!</pre>"; } // Setup our API access $this->load->library('twitter'); $twitter = new Twitter(array('consumerKey' => $this->consumer_key, 'consumerSecret' => $this->consumer_secret)); $twitter->setOAuthToken($this->oauth_access_token); $twitter->setOAuthTokenSecret($this->oauth_access_secret); // Go and get our activity information $service_url = registry_url('services/rda/getLatestActivityBySubject/' . $this->num_days_history); $data = @json_decode(@file_get_contents($service_url), true); if (!isset($data['results']) || count($data['results']) == 0) { echo "No activity information to be displayed. No updates matched the query at " . $service_url; return; } else { echo "<h4>Found " . count($data['results']) . " updates for the past " . $this->num_days_history . " days...</h4>"; // Reverse the sort order so largest update counts come last (i.e. highest on the Twitter feed) krsort($data['results']); foreach ($data['results'] as $idx => $update) { try { // Format our tweet message $tweet = sprintf("%d %s added with the subject '%s' #ANZSRC%s", $update['num_records'], pluralise("collection", $update['num_records']), ellipsis($update['value']), $update['notation']); echo "Sending Tweet: <i>" . $tweet . "</i>..."; flush(); if (!$dryrun) { $twitter->statusesUpdate($tweet); echo "sent " . BR; flush(); } sleep(0.5); // Pause between big chunks of tweets if ($idx % 5 == 0) { sleep(5); } } catch (TwitterException $e) { echo BR . BR . "Unable to send Tweet to Twitter API: " . $e->getMessage() . BR . BR; } catch (Exception $e) { echo BR . BR . "Unknown Exception: " . $e->getMessage() . BR . BR; } } } return; }
function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; $twitter_username = empty($instance['twitter_username']) ? ' ' : apply_filters('widget_title', $instance['twitter_username']); $consumerKey = empty($instance['consumerKey']) ? ' ' : apply_filters('widget_title', $instance['consumerKey']); $consumerSecret = empty($instance['consumerSecret']) ? ' ' : apply_filters('widget_title', $instance['consumerSecret']); $accessToken = empty($instance['accessToken']) ? ' ' : apply_filters('widget_title', $instance['accessToken']); $accessTokenSecret = empty($instance['accessTokenSecret']) ? ' ' : apply_filters('widget_title', $instance['accessTokenSecret']); $title = $instance['title']; $items = empty($instance['items']) ? ' ' : apply_filters('widget_title', $instance['items']); if (!is_numeric($items)) { $items = 5; } if (empty($title)) { $title = 'Recent Tweets'; } if (!empty($items) && !empty($twitter_username)) { // user timeline include_once TEMPLATEPATH . "/lib/twitter/twitter.class.php"; // ENTER HERE YOUR CREDENTIALS (see readme.txt) $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); $tweets = $twitter->load(Twitter::ME); //$obj_twitter = new Twitter($twitter_username); //$tweets = $obj_twitter->get($items); if (!empty($tweets)) { echo '<h3 class="widget-title">' . $title . '</h3>'; echo '<ul id="twitter_list">'; $i = 1; foreach ($tweets as $tweet) { if ($i > $items) { break; } echo '<li>'; if (isset($tweet->text)) { echo '<a class="tweet_link" href="http://twitter.com/' . $tweet->user->screen_name . '">' . $tweet->text . '</a>'; } echo '</li>'; $i++; } echo '</ul>'; } } echo $after_widget; }
function TwitterFriends() { $friends = Twitter::get_list_of_friends($this->owner->TwitterUserID); $set = new DataObjectSet(); foreach ($friends as $friend) { $set->push(new ArrayData(array('ID' => $friend["id"], 'Name' => $friend["name"], 'PictureURL' => $friend["profile_image_url"]))); } return $set; }
protected function get($name, $default = null) { if (!$this->twitter->connected()) { return $default; } if (isset($this->user[$name])) { return $this->user[$name]; } return $default; }
public function handle($quote) { $id = $quote->id; $username = $quote->user->username; $title = $quote->title; $url = URL::route('quote', [$quote->id]); $message = "#{$id} ({$username}): {$title} {$url}"; Twitter::postTweet(array('status' => $message, 'format' => 'json')); Irc::broadcast($message); }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $t = new Twitter(sfConfig::get('twitter_username'), sfConfig::get('twitter_password')); $last_dm = RawDmPeer::getLastDM($connection); $since = null; if ($last_dm) { $since = $last_dm->getDmId(); } $dms = $t->getDirectMessages($since); foreach ($dms as $dm) { $rawdm = RawDmPeer::saveDirectMessage($dm, $connection); if ($rawdm instanceof RawDm) { $need = NeedPeer::convertDirectMessage($rawdm, $connection); } else { var_dump($rawdm); } } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $t = new Twitter(sfConfig::get('twitter_username'), sfConfig::get('twitter_password')); $last_message = RawMessagePeer::getLastMessage($connection); $since = null; if ($last_message) { $since = $last_message->getMessageId(); } $messages = $t->getMentionsReplies($since); foreach ($messages as $message) { $rawmessage = RawMessagePeer::saveMessage($message, $connection); if ($rawmessage instanceof RawMessage) { $need = NeedPeer::convertMessage($rawmessage, $con); } else { var_dump($rawmessage); } } }