當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Twitter類代碼示例

本文整理匯總了PHP中Twitter的典型用法代碼示例。如果您正苦於以下問題:PHP Twitter類的具體用法?PHP Twitter怎麽用?PHP Twitter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Twitter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: sendMessage

 public function sendMessage($message)
 {
     try {
         Twitter::postTweet(array('status' => substr($message, 0, 140), 'format' => 'json'));
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
 }
開發者ID:andrewchng,項目名稱:cSystem,代碼行數:8,代碼來源:TwitterSender.php

示例2: loadUserByUsername

 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;
 }
開發者ID:gitter-badger,項目名稱:Doctors,代碼行數:26,代碼來源:TwitterUserProvider.php

示例3: twitterUserTimeLine

 public function twitterUserTimeLine()
 {
     $twit = new Twitter();
     $user = $this->params[0];
     $count = (int) $this->params[1];
     return $twit->getUserTimeLine($user, $count);
 }
開發者ID:rezaprima,項目名稱:icms,代碼行數:7,代碼來源:servicecontroller.php

示例4: action_results

 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);
 }
開發者ID:nayeonk,項目名稱:ITP404-MVCpart1,代碼行數:8,代碼來源:twitter.php

示例5: twitter

 public static function twitter($title)
 {
     $twitter = new Twitter();
     if ($twitter->tweet($title)) {
         return true;
     }
     return false;
 }
開發者ID:sydlawrence,項目名稱:SocialFeed,代碼行數:8,代碼來源:log.php

示例6: twitter

 /**
  * 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;
 }
開發者ID:jobinpankajan,項目名稱:WeGive,代碼行數:12,代碼來源:user.php

示例7: twitteraccessAction

 /** 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);
     }
 }
開發者ID:lesleyauk,項目名稱:findsorguk,代碼行數:18,代碼來源:OauthController.php

示例8: post_to_twitter

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);
}
開發者ID:AnsonX10,項目名稱:bitfighter.tools,代碼行數:11,代碼來源:post_twitter.php

示例9: __construct

 function __construct($username = 'beirutspring')
 {
     // 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}";
     }
 }
開發者ID:aboustayyef,項目名稱:deprecated_lb_l5,代碼行數:11,代碼來源:twitterAccountScraper.php

示例10: execute

 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);
     }
 }
開發者ID:pascaldevink,項目名稱:twneed,代碼行數:12,代碼來源:twneedTweetNeedsTask.class.php

示例11: _checkForTwitterUpdates

 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);
     }
 }
開發者ID:robfrawley,項目名稱:cad,代碼行數:53,代碼來源:ControllerMain.php

示例12: login_with_oauth

 /**
  * 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' => '/');
 }
開發者ID:jobinpankajan,項目名稱:WeGive,代碼行數:16,代碼來源:twittercontroller.php

示例13: postTweet

 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));
     }
 }
開發者ID:CanAvci,項目名稱:Twitter-Search,代碼行數:14,代碼來源:TwitterController.php

示例14: broadcast

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);
    }
}
開發者ID:rmunro,項目名稱:SMS-Turks,代碼行數:48,代碼來源:broadcast.php

示例15: twSlider

 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;
 }
開發者ID:amdad,項目名稱:portfolio,代碼行數:16,代碼來源:functions.php


注:本文中的Twitter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。