本文整理汇总了PHP中Tweet类的典型用法代码示例。如果您正苦于以下问题:PHP Tweet类的具体用法?PHP Tweet怎么用?PHP Tweet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tweet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: loadTweets
public function loadTweets()
{
$conn = $this->connection;
$sqlQuery = "SELECT user_id, tweets.id, text FROM tweets INNER JOIN users ON tweets.user_id = users.id ORDER BY tweets.created_at DESC";
$result = $conn->query($sqlQuery);
if ($result->num_rows > 0) {
while (list($userId, $tweetId, $text) = $result->fetch_array(MYSQLI_NUM)) {
$tweet = new Tweet($conn);
$tweet->setUserId($userId);
$tweet->setText($text);
$tweet->setId($tweetId);
$this->arrayWithTweets[] = $tweet;
}
return true;
} else {
return false;
}
}
开发者ID:Witoso,项目名称:twitter_app,代码行数:18,代码来源:TweetsLoader.php
示例17: reply
public function reply($id)
{
try {
$tweet = new Tweet($id);
$comment = new TweetComment();
$comment->setTweetId($tweet->getId());
$comment->setProfileId(UserHelper::getProfileId());
$comment->setContent(trim(fRequest::get('tweet-comment')));
if (strlen($comment->getContent()) < 1) {
throw new fValidationException('回复长度不能少于1个字符');
}
if (strlen($comment->getContent()) > 140) {
throw new fValidationException('回复长度不能超过140个字符');
}
$comment->store();
} catch (fException $e) {
// TODO
}
fURL::redirect(SITE_BASE . '/profile/' . $tweet->getProfileId() . '#tweet/' . $tweet->getId());
}
开发者ID:daerduoCarey,项目名称:xiaoyou,代码行数:20,代码来源:TweetController.php
示例18: createFromJSON
public static function createFromJSON($json)
{
$tweets = json_decode($json, true);
if (!is_array($tweets) || !isset($tweets['results'])) {
throw new InvalidArgumentException('Unable to decode JSON response');
}
$tweetCollection = array();
foreach ($tweets['results'] as $tweetArray) {
$tweetCollection[] = Tweet::createFromArray($tweetArray);
}
return new self($tweetCollection);
}
开发者ID:buraksahin59,项目名称:phptwitterbot,代码行数:12,代码来源:TweetCollection.class.php
示例19: do_update_if_needed
function do_update_if_needed($twitster)
{
if (time_for_refresh()) {
if (file_exists(UPDATE_PID_FILE)) {
twitlog("Time for an update, but one is already in progress. Skipping.");
} else {
twitlog("It is time to refresh the cache, beginning now.");
$tweets = Tweet::find();
$since = is_array($tweets) && $tweets[0] ? $tweets[0]->id : false;
$twitster->refresh($since);
}
}
}
开发者ID:laiello,项目名称:twitster,代码行数:13,代码来源:util.php
示例20: show
public function show($id = null)
{
$account = $this->load_account($id);
$this->assign('account', $account);
$page = 1;
if ($this->GetData('page')) {
$page = $this->GetData('page');
}
$id = mysql_real_escape_string($account->id);
$tweets = Tweet::paginate("twitter_accounts.id = '{$id}'", "tweets.publish_at DESC, tweets.id DESC", $page, 20);
$this->assign('tweets', $tweets);
$this->title = "Twitter Account :: {$account->name}";
$this->render('twitter_account/show.tpl');
}
开发者ID:ItsHaden,项目名称:epicLanBootstrap,代码行数:14,代码来源:twitter_account.controller.php
注:本文中的Tweet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论