Exemplo n.º 1
0
 public function getCallback()
 {
     $token = Input::get('oauth_token');
     $verifier = Input::get('oauth_verifier');
     $accessToken = Twitter::oAuthAccessToken($token, $verifier);
     if (isset($accessToken['user_id'])) {
         $user_id = $accessToken['user_id'];
         $user = User::find($user_id);
         if (empty($user)) {
             $user = new User();
             $user->id = $user_id;
         }
         Twitter::setOAuthToken($accessToken['oauth_token']);
         Twitter::setOAuthTokenSecret($accessToken['oauth_token_secret']);
         $timeline = Twitter::statusesUserTimeline($user->id);
         $user->screen_name = $accessToken['screen_name'];
         $user->profile_image_url = $timeline[0]['user']['profile_image_url'];
         $user->oauth_token = $accessToken['oauth_token'];
         $user->oauth_token_secret = $accessToken['oauth_token_secret'];
         $user->save();
         Auth::login($user);
         return Redirect::to('/');
         exit;
     } else {
         return Redirect::to('login')->with('message', 'Twitter認証できませんでした。');
         exit;
     }
 }
Exemplo n.º 2
0
$twitter->setOAuthTokenSecret($secret);
?>

<br/><br/>
<a href='/classes/viewSource/?path=<?php 
echo $_SERVER['PHP_SELF'];
?>
' target='_blank'>View Source</a><br/><br/><br/>
<a href='http://classes.verkoyen.eu/modules/twitter_oauth/files/php_twitter_2_0_3.zip'>Download twitter.php (wrapper library)</a><br/><br/>

<?php 
/*-------------------------------------------------------------------------------------------------
GET USER TIMELINE
-------------------------------------------------------------------------------------------------*/
echo "<h2>User Timeline (upennClassDemos)</h2>";
$userTimeline = $twitter->statusesUserTimeline();
# Loop through the results
foreach ($userTimeline as $thisTweet) {
    # Echo out each tweet
    echo $thisTweet['text'] . "<br/>";
}
echo "<br/><br/>";
# For debugging purposes we can echo out the full array of the results
//print_r($userTimeline);
/*-------------------------------------------------------------------------------------------------
TRENDS
-------------------------------------------------------------------------------------------------*/
echo "<h2>Trends</h2>";
$trendsDaily = $twitter->trends();
# Loop through the results
foreach ($trendsDaily['trends'] as $thisTrend) {
Exemplo n.º 3
0
 public function showall()
 {
     if (!empty($this->config['consumer_key'])) {
         // create instance
         $twitter = new Twitter($this->config['consumer_key'], $this->config['consumer_secret']);
         // set tokens
         $twitter->setOAuthToken($this->config['oauth_token']);
         $twitter->setOAuthTokenSecret($this->config['oauth_token_secret']);
         $mytwitteracct = $twitter->accountVerifyCredentials();
         switch ($this->config['typestatus']) {
             case 1:
                 // get users timeline including retweets
                 $tweets = $twitter->statusesUserTimeline(null, null, null, null, $this->config['twlimit'], null, null, true);
                 break;
             case 2:
                 // get friends timeline
                 $tweets = $twitter->statusesFriendsTimeline(null, null, $this->config['twlimit']);
                 break;
             case 3:
                 // get mentions
                 $tweets = $twitter->statusesMentions(null, null, $this->config['twlimit']);
                 break;
             case 4:
                 // get public timeline
                 $tweets = $twitter->statusesPublicTimeline();
                 break;
             default:
                 // get home timeline
                 $tweets = $twitter->statusesHomeTimeline(null, null, $this->config['twlimit']);
                 break;
         }
         if ($this->config['twlimit']) {
             $tweets = array_slice($tweets, 0, $this->config['twlimit'], true);
         }
         $retweets = $twitter->statusesRetweetedByMe(null, null, $this->config['twlimit']);
         foreach ($tweets as $key => $value) {
             $tweets[$key]['retweetedbyme'] = false;
             if (strpos($value['text'], 'RT ') === false) {
                 $tweets[$key]['text'] = $this->twitterify($value['text']);
                 $tweets[$key]['screen_name'] = $value['user']['screen_name'];
                 $tweets[$key]['image'] = $value['user']['profile_image_url'];
                 $tweets[$key]['via'] = $value['source'];
                 $tweets[$key]['ours'] = $value['user']['id'] == $mytwitteracct['id'] ? true : false;
             } else {
                 // we're a retweet
                 $tweets[$key]['text'] = $this->twitterify(substr($value['text'], strpos($value['text'], ':') + 2));
                 // strip out RT text
                 $tweets[$key]['screen_name'] = isset($value['retweeted_status']['user']['screen_name']) ? $value['retweeted_status']['user']['screen_name'] : 'Unknown';
                 $tweets[$key]['image'] = isset($value['retweeted_status']['user']['profile_image_url']) ? $value['retweeted_status']['user']['profile_image_url'] : '';
                 if ($value['user']['id'] == $mytwitteracct['id']) {
                     $tweets[$key]['via'] = $value['source'];
                     $tweets[$key]['retweetedbyme'] = true;
                 } else {
                     $tweets[$key]['via'] = $value['source'] . ' (<img src="framework/modules/twitter/assets/images/rt.png" title="retweet by" alt="RT by"/> ' . $value['user']['screen_name'] . ')';
                 }
                 $tweets[$key]['ours'] = $value['user']['id'] == $mytwitteracct['id'] ? true : false;
             }
             //			    $tweets[$key]['created_at'] = strtotime($value['created_at']); // convert to unix time
             $tweets[$key]['created_at'] = expDateTime::relativeDate(strtotime($value['created_at']));
             // convert to unix time
             if (!isset($value['retweeted_status'])) {
                 $tweets[$key]['retweeted_status'] = false;
             }
             foreach ($retweets as $rekey => $revalue) {
                 if ($tweets[$key]['id'] == $retweets[$rekey]['retweeted_status']['id']) {
                     $tweets[$key]['retweetedbyme'] = true;
                     break;
                 }
             }
         }
         assign_to_template(array('items' => $tweets));
     }
 }