当前位置: 首页>>代码示例>>PHP>>正文


PHP Tweet类代码示例

本文整理汇总了PHP中Tweet的典型用法代码示例。如果您正苦于以下问题:PHP Tweet类的具体用法?PHP Tweet怎么用?PHP Tweet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Tweet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process_json_file_timeline

function process_json_file_timeline($filepath, $dbh)
{
    global $tweets_processed, $tweets_failed, $tweets_success, $valid_timeline, $empty_timeline, $invalid_timeline, $populated_timeline, $total_timeline, $all_tweet_ids, $all_users, $bin_name;
    $tweetQueue = new TweetQueue();
    $total_timeline++;
    ini_set('auto_detect_line_endings', true);
    $handle = @fopen($filepath, "r");
    if ($handle) {
        while (($buffer = fgets($handle, 40960)) !== false) {
            $tweet = json_decode($buffer, true);
            //var_export($tweet); print "\n\n";
            $buffer = "";
            $t = new Tweet();
            $t->fromJSON($tweet);
            if (!$t->isInBin($bin_name)) {
                $tweetQueue->push($t, $bin_name);
                if ($tweetQueue->length() > 100) {
                    $tweetQueue->insertDB();
                }
                $all_users[] = $t->from_user_id;
                $all_tweet_ids[] = $t->id;
                $tweets_processed++;
            }
            print ".";
        }
        if (!feof($handle)) {
            echo "Error: unexpected fgets() fail\n";
        }
        fclose($handle);
    }
    if ($tweetQueue->length() > 0) {
        $tweetQueue->insertDB();
    }
}
开发者ID:01123578,项目名称:dmi-tcat,代码行数:34,代码来源:import-jsondump.php

示例2: getTweetsInJsonFile

 /**
  * Returns an array of Tweet objects that are populated from a Twitter JSON file.
  *
  * @param string $filename
  * @return array|false
  */
 public function getTweetsInJsonFile($filename)
 {
     $tweets = [];
     if (!file_exists($filename) || file_exists($filename) && !is_readable($filename)) {
         return false;
     }
     $jsonString = file_get_contents($filename);
     if ($jsonString === false) {
         return false;
     }
     // the twitter format includes extra JS code, but we just want the JSON array
     $pattern = '/\\[.*\\]/s';
     $matchError = preg_match($pattern, $jsonString, $matches);
     // $matchError can be zero or false if not found or there was a failure
     if (!$matchError) {
         return false;
     }
     $jsonArrayString = $matches[0];
     $jsonTweets = json_decode($jsonArrayString);
     foreach ($jsonTweets as $tweet) {
         $t = new Tweet();
         $t->loadFromJsonObject($tweet);
         $tweets[] = $t;
     }
     return $tweets;
 }
开发者ID:Darathor,项目名称:archive-my-tweets,代码行数:32,代码来源:Importer.php

示例3: process_data

 private function process_data($data)
 {
     foreach ($data->results as $tweet) {
         $tweet = new Tweet($tweet->id_str);
         $tweet->save();
         $this->tids[] = $tweet->tid;
     }
 }
开发者ID:nodefortytwo,项目名称:freshlytics,代码行数:8,代码来源:twitter_rest_query.php

示例4: parseTimeline

 public function parseTimeline($timeline)
 {
     foreach ($timeline as $tweet) {
         $item = new Tweet();
         $item->setId($tweet->id)->setTitle($tweet->text)->setDescription($tweet->text)->setPubDate($tweet->created_at)->setPlace($tweet->place)->setUsername($tweet->user->screen_name)->setUserId($tweet->user->id);
         $this->addTweet($item);
     }
 }
开发者ID:krolow,项目名称:twitter-rss,代码行数:8,代码来源:RSS.php

示例5: search

function search($idlist)
{
    global $twitter_keys, $current_key, $all_users, $all_tweet_ids, $bin_name, $dbh, $tweetQueue;
    $keyinfo = getRESTKey(0);
    $current_key = $keyinfo['key'];
    $ratefree = $keyinfo['remaining'];
    print "current key {$current_key} ratefree {$ratefree}\n";
    $tmhOAuth = new tmhOAuth(array('consumer_key' => $twitter_keys[$current_key]['twitter_consumer_key'], 'consumer_secret' => $twitter_keys[$current_key]['twitter_consumer_secret'], 'token' => $twitter_keys[$current_key]['twitter_user_token'], 'secret' => $twitter_keys[$current_key]['twitter_user_secret']));
    // by hundred
    for ($i = 0; $i < sizeof($idlist); $i += 100) {
        if ($ratefree <= 0 || $ratefree % 10 == 0) {
            $keyinfo = getRESTKey($current_key);
            $current_key = $keyinfo['key'];
            $ratefree = $keyinfo['remaining'];
            $tmhOAuth = new tmhOAuth(array('consumer_key' => $twitter_keys[$current_key]['twitter_consumer_key'], 'consumer_secret' => $twitter_keys[$current_key]['twitter_consumer_secret'], 'token' => $twitter_keys[$current_key]['twitter_user_token'], 'secret' => $twitter_keys[$current_key]['twitter_user_secret']));
        }
        $q = $idlist[$i];
        $n = $i + 1;
        while ($n < $i + 100) {
            if (!isset($idlist[$n])) {
                break;
            }
            $q .= "," . $idlist[$n];
            $n++;
        }
        $params = array('id' => $q);
        $code = $tmhOAuth->user_request(array('method' => 'GET', 'url' => $tmhOAuth->url('1.1/statuses/lookup'), 'params' => $params));
        $ratefree--;
        if ($tmhOAuth->response['code'] == 200) {
            $data = json_decode($tmhOAuth->response['response'], true);
            if (is_array($data) && empty($data)) {
                // all tweets in set are deleted
                continue;
            }
            $tweets = $data;
            $tweet_ids = array();
            foreach ($tweets as $tweet) {
                $t = new Tweet();
                $t->fromJSON($tweet);
                if (!$t->isInBin($bin_name)) {
                    $all_users[] = $t->from_user_id;
                    $all_tweet_ids[] = $t->id;
                    $tweet_ids[] = $t->id;
                    $tweetQueue->push($t, $bin_name);
                }
                print ".";
            }
            sleep(1);
        } else {
            echo "Failure with code " . $tmhOAuth->response['response']['code'] . "\n";
            var_dump($tmhOAuth->response['response']['info']);
            var_dump($tmhOAuth->response['response']['error']);
            var_dump($tmhOAuth->response['response']['errno']);
            die;
        }
        $tweetQueue->insertDB();
    }
}
开发者ID:01123578,项目名称:dmi-tcat,代码行数:58,代码来源:lookup.php

示例6: getPostData

 /**
  * Get relevant properly sized data for using the Twitter API.
  *
  * @param Tweet $tweet
  *
  * @return array
  */
 protected function getPostData(Tweet $tweet)
 {
     $message = $tweet->getMessage();
     $message->rewind();
     $status = $message->getContents();
     if (0 === $tweet->getMediaId()) {
         return ['status' => substr($status, 0, 140)];
     }
     return ['status' => substr($status, 0, 110), 'media_ids' => $tweet->getMediaId()];
 }
开发者ID:jimlind,项目名称:pie7o,代码行数:17,代码来源:StatusUpdater.php

示例7: search

function search($keywords, $max_id = null)
{
    global $twitter_keys, $current_key, $ratefree, $bin_name, $dbh, $tweetQueue;
    $ratefree--;
    if ($ratefree < 1 || $ratefree % 10 == 0) {
        $keyinfo = getRESTKey($current_key, 'search', 'tweets');
        $current_key = $keyinfo['key'];
        $ratefree = $keyinfo['remaining'];
    }
    $tmhOAuth = new tmhOAuth(array('consumer_key' => $twitter_keys[$current_key]['twitter_consumer_key'], 'consumer_secret' => $twitter_keys[$current_key]['twitter_consumer_secret'], 'token' => $twitter_keys[$current_key]['twitter_user_token'], 'secret' => $twitter_keys[$current_key]['twitter_user_secret']));
    $params = array('q' => $keywords, 'count' => 100);
    if (isset($max_id)) {
        $params['max_id'] = $max_id;
    }
    $code = $tmhOAuth->user_request(array('method' => 'GET', 'url' => $tmhOAuth->url('1.1/search/tweets'), 'params' => $params));
    if ($tmhOAuth->response['code'] == 200) {
        $data = json_decode($tmhOAuth->response['response'], true);
        $tweets = $data['statuses'];
        $tweet_ids = array();
        foreach ($tweets as $tweet) {
            $t = new Tweet();
            $t->fromJSON($tweet);
            $tweet_ids[] = $t->id;
            if (!$t->isInBin($bin_name)) {
                $tweetQueue->push($t, $bin_name);
                if ($tweetQueue->length() > 100) {
                    $tweetQueue->insertDB();
                }
                print ".";
            }
        }
        if (!empty($tweet_ids)) {
            print "\n";
            if (count($tweet_ids) <= 1) {
                print "no more tweets found\n\n";
                return false;
            }
            $max_id = min($tweet_ids);
            print "max id: " . $max_id . "\n";
        } else {
            print "0 tweets found\n\n";
            return false;
        }
        sleep(1);
        search($keywords, $max_id);
    } else {
        echo $tmhOAuth->response['response'] . "\n";
        if ($tmhOAuth->response['response']['errors']['code'] == 130) {
            // over capacity
            sleep(1);
            search($keywords, $max_id);
        }
    }
}
开发者ID:petethegreek,项目名称:dmi-tcat,代码行数:54,代码来源:search.php

示例8: load

  public function load($id) {
    $result=HypertableConnection::query("SELECT * FROM tweet ".
                "WHERE ROW='$id'");
    if (!$result or !count($result->cells))
      return null;

    $tweet=new Tweet();
    $tweet->setId($id);
    $tweet->setTimestamp($result->cells[0]->key->timestamp);
    $tweet->setMessage($result->cells[0]->value);
    return $tweet;
  }
开发者ID:nimishzynga,项目名称:hypertable,代码行数:12,代码来源:TweetTable.php

示例9: classify

 /**
  * Turn the array of results to an object array of Tweets.
  *
  * @param array $data Array of tweet results
  *
  * @return array An array of Tweets
  */
 protected function classify($data)
 {
     if (!isset($data) || empty($data)) {
         return;
     }
     $tweets = [];
     foreach ($data as $tweet) {
         $tweet_obj = new Tweet();
         $tweets[] = $tweet_obj->set_data($tweet);
     }
     return $tweets;
 }
开发者ID:rubendgr,项目名称:lunr,代码行数:19,代码来源:Search.php

示例10: store

 public function store(Request $request)
 {
     $type = $request->get('type');
     $tweet = Tweet::find($id);
     if (!$tweet) {
         $tweet = new Tweet();
         $tweet[$type] = 1;
     }
     $tweet->id = $request->get('id');
     $tweet->text = $request->get('text');
     $tweet->increment($type);
     $tweet->save();
     return $request->all();
 }
开发者ID:Niiwill,项目名称:pizzaApp,代码行数:14,代码来源:AdminController.php

示例11: showTweet

 public function showTweet($tweet_id)
 {
     if (Request::ajax()) {
         $tweet = Tweet::where('tweet_id', '=', $tweet_id)->destroy();
         return Response::json(true);
     }
 }
开发者ID:judavi,项目名称:laravel-challenge,代码行数:7,代码来源:TweetsController.php

示例12: data

 public static function data()
 {
     // Haetaan kaikki twiitit tietokannasta
     $tweets = Tweet::all();
     // Renderöidään views kansiossa sijaitseva tiedosto tietokannat.html muuttujan $tweets datalla
     View::make('data.html', array('tweets' => $tweets));
 }
开发者ID:hegemonni,项目名称:Tsoha-Bootstrap,代码行数:7,代码来源:tweets_controller.php

示例13: get_posts

 public function get_posts()
 {
     $url = add_query_arg(array('screen_name' => self::$username, 'exclude_replies' => 'true'), self::$endpoint);
     $response = wp_remote_get($url, array('headers' => array('Authorization' => 'Bearer ' . self::$bearer_token)));
     $r = json_decode(wp_remote_retrieve_body($response));
     if ($r) {
         foreach ($r as $raw_tweet) {
             $tweet = new Tweet($raw_tweet);
             $social_post = $tweet->generate_socialpost();
             if (!$social_post->exists()) {
                 $social_post->save();
             } else {
             }
         }
     }
 }
开发者ID:TMBR,项目名称:johnjohn,代码行数:16,代码来源:twitter.php

示例14: process_json_file_timeline

function process_json_file_timeline($filepath, $dbh)
{
    global $tweets_processed, $tweets_failed, $tweets_success, $valid_timeline, $empty_timeline, $invalid_timeline, $populated_timeline, $total_timeline, $all_tweet_ids, $all_users, $bin_name;
    $tweetQueue = new TweetQueue();
    $total_timeline++;
    $filestr = file_get_contents($filepath);
    // sylvester stores multiple json exports in the same file,
    // in order to decode it we will need to split it into its respective individual exports
    $jsons = explode("}][{", $filestr);
    print count($jsons) . " jsons found\n";
    foreach ($jsons as $json) {
        if (substr($json, 0, 2) != "[{") {
            $json = "[{" . $json;
        }
        if (substr($json, -2) != "}]") {
            $json = $json . "}]";
        }
        $timeline = json_decode($json);
        if (is_array($timeline)) {
            $valid_timeline++;
            if (!empty($timeline)) {
                $populated_timeline++;
            } else {
                $empty_timeline++;
            }
        } else {
            $invalid_timeline++;
        }
        foreach ($timeline as $tweet) {
            $t = new Tweet();
            $t->fromJSON($tweet);
            if (!$t->isInBin($bin_name)) {
                $tweetQueue->push($t, $bin_name);
                if ($tweetQueue->length() > 100) {
                    $tweetQueue->insertDB();
                }
                $all_users[] = $t->user->id;
                $all_tweet_ids[] = $t->id;
                $tweets_processed++;
            }
        }
    }
    if ($tweetQueue->length() > 0) {
        $tweetQueue->insertDB();
    }
}
开发者ID:petethegreek,项目名称:dmi-tcat,代码行数:46,代码来源:import-timeline.php

示例15: addFavoris

 public static function addFavoris($req_twitter, $name_id)
 {
     foreach ($req_twitter as $key => $value) {
         Tweet::create(array('name_id' => $name_id->id, 'id_str' => $value->id, 'screen_name' => $value->user->screen_name, 'name' => $value->user->name, 'profile_image_url' => $value->user->profile_image_url, 'text' => $value->text, 'date_tweet' => $value->created_at));
         $max_id = $value->id;
     }
     return $max_id;
 }
开发者ID:devsprite,项目名称:twitterSearchFavorite,代码行数:8,代码来源:TwitterFav.php


注:本文中的Tweet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。