public function sendMessage($message) { try { Twitter::postTweet(array('status' => substr($message, 0, 140), 'format' => 'json')); } catch (Exception $e) { var_dump($e->getMessage()); } }
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); }
/** * Execute the console command. * */ public function fire() { # update articles # discover hot articles try { $hot_profile = ['1' => ['min_age' => 0, 'max_age' => 1, 'min_view_num' => 2000, 'min_hotlist_top_up_num' => 40], '2' => ['min_age' => 1, 'max_age' => 2, 'min_view_num' => 3000, 'min_hotlist_top_up_num' => 60], '3' => ['min_age' => 2, 'max_age' => 5, 'min_view_num' => 5000, 'min_hotlist_top_up_num' => 100], '4' => ['min_age' => 5, 'max_age' => 10, 'min_view_num' => 9000, 'min_hotlist_top_up_num' => 200]]; $profile = $hot_profile[$this->argument('type')]; $articles_to_update = ArticleEntry::whereRaw('hot = FALSE AND date <= now() - INTERVAL ? HOUR AND date >= now() - INTERVAL ? HOUR', array($profile['min_age'], $profile['max_age']))->get(); foreach ($articles_to_update as $article_to_update) { $article = new Article($article_to_update->article_id); $article->sync(); if ($article->data['view_num'] > $profile['min_view_num'] or isset($article->data['hotlist']) && $article->data['hotlist'][0]['up'] > $profile['min_hotlist_top_up_num']) { $article_to_update->hot = true; $article_to_update->save(); $hotlist_top = isset($article->data['hotlist']) ? ' HotlistTopUps: ' . $article->data['hotlist'][0]['up'] : ''; mlog('found hot article: ' . $article->data['id'] . ' ' . $article->data['title'] . ' ' . $article->data['date'] . ' Views: ' . $article->data['view_num'] . $hotlist_top); } } } catch (Exception $ex) { Log::error('unable to update articles: ' . $ex->getMessage()); throw $ex; } # push articles $article_to_push = ArticleEntry::whereRaw('hot = TRUE AND pushed = FALSE')->orderBy('date', 'desc')->first(); if ($article_to_push) { $article_to_push->pushed = true; $article_to_push->save(); mlog('pushing article id: ' . $article_to_push->article_id . ' content: ' . $article_to_push->toTimeline()); try { Twitter::postTweet(array('status' => $article_to_push->toTimeline(), 'format' => 'json')); } catch (Exception $ex) { Log::error('unable to push article to twitter: ' . $ex->getMessage()); } /* try { # (new Weibo())->postWeibo($article_to_push->toTimeline()); $ret = postWeiboBySAE($article_to_push->toTimeline()); if ($ret != '发送成功') throw new Exception($ret); } catch (Exception $ex) { Log::error('unable to push article to weibo: ' . $ex->getMessage()); }*/ } }
Route::get('/', function () { return view('home'); }); Route::post('fetch', function () { require_once 'app/Classes/OpenGraph.php'; $graph = OpenGraph::fetch(Input::get('url')); foreach ($graph as $key => $value) { $output[$key] = $value; } return $output; }); Route::post('sendtweet', function () { $file = file_get_contents(Input::get('image')); $file = base64_encode($file); $uploaded_media = Twitter::uploadMedia(['media_data' => $file]); return Twitter::postTweet(['status' => Input::get('text'), 'media_ids' => $uploaded_media->media_id_string]); }); Route::get('twitter/login', ['as' => 'twitter.login', function () { // your SIGN IN WITH TWITTER button should point to this route $sign_in_twitter = true; $force_login = false; // Make sure we make this request w/o tokens, overwrite the default values in case of login. Twitter::reconfig(['token' => '', 'secret' => '']); $token = Twitter::getRequestToken(route('twitter.callback')); if (isset($token['oauth_token_secret'])) { $url = Twitter::getAuthorizeURL($token, $sign_in_twitter, $force_login); Session::put('oauth_state', 'start'); Session::put('oauth_request_token', $token['oauth_token']); Session::put('oauth_request_token_secret', $token['oauth_token_secret']); return Redirect::to($url); }
public static function tweet($obj, $type) { if ($type === 'mp3') { $status = '#NouvoMizik '; } elseif ($type === 'mp4') { $status = '#NouvoVideyo '; } $status .= "{$obj->name} " . URL::to("/{$type}/{$obj->id}") . " via @TKPMizik | @TiKwenPam #" . $obj->category->slug; //Auto-Post Tweet Twitter::postTweet(['status' => $status, 'format' => 'json']); }
/** * Post article to twitter with cover image * * @param $article * @return void */ private function tweet($article) { Tweet::reconfig(['token' => Auth::user()->twitter_token->token, 'secret' => Auth::user()->twitter_token->secret]); $media = Tweet::uploadMedia(['media' => file_get_contents($article->cover()->url)]); Tweet::postTweet(['status' => $article->title . ' ' . url($article->slug), 'media_ids' => $media->media_id_string]); }