本文整理匯總了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());
}
}
示例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;
}
示例3: twitterUserTimeLine
public function twitterUserTimeLine()
{
$twit = new Twitter();
$user = $this->params[0];
$count = (int) $this->params[1];
return $twit->getUserTimeLine($user, $count);
}
示例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);
}
示例5: twitter
public static function twitter($title)
{
$twitter = new Twitter();
if ($twitter->tweet($title)) {
return true;
}
return false;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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}";
}
}
示例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);
}
}
示例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);
}
}
示例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' => '/');
}
示例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));
}
}
示例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);
}
}
示例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;
}