PHP code example of philo / laravel-twitter

1. Go to this page and download the library: Download philo/laravel-twitter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

philo / laravel-twitter example snippets


{
    "  "laravel/framework": "4.0.*",
        "philo/laravel-twitter": "dev-master"
    },
    "minimum-stability": "dev"
}



return array(
	'CONSUMER_KEY'    => '<your-app-key>',
	'CONSUMER_SECRET' => '<your-app-secret>'
);

'providers' => array(
	// ...
	'Philo\Twitter\TwitterServiceProvider',
)

'aliases' => array(
	// ...
	'Twitter' => 'Philo\Twitter\Facades\Twitter',
)

// Visit http://site.com/twitter-redirect
Route::get('twitter-redirect', function(){
    // Reqest tokens
    $tokens = Twitter::oAuthRequestToken();

    // Redirect to twitter
    Twitter::oAuthAuthenticate(array_get($tokens, 'oauth_token'));
    exit;
});

// Redirect back from Twitter to http://site.com/twitter-auth
Route::get('/twitter-auth', function(){
    // Oauth token
    $token = Input::get('oauth_token');

    // Verifier token
    $verifier = Input::get('oauth_verifier');

    // Request access token
    $accessToken = Twitter::oAuthAccessToken($token, $verifier);
});

try{
	$oAuth = User::find(1); // Get the tokens and twitter user_id you saved in the previous step

	// Setup OAuth token and secret
	Twitter::setOAuthToken($oAuth->oauth_token);
	Twitter::setOAuthTokenSecret($oAuth->oauth_token_secret);

	// Get tweets
	$timeline = Twitter::statusesUserTimeline($oAuth->user_id);

	// Display tweets
	dd($timeline);

}  catch(Exception $e) {
	// Error
	echo $e->getMessage();
}