PHP code example of codezero / twitter

1. Go to this page and download the library: Download codezero/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/ */

    

codezero / twitter example snippets

 
'providers' => [
    'CodeZero\Twitter\TwitterServiceProvider'
]
 
php artisan config:publish codezero/twitter
 
php artisan vendor:publish --provider="CodeZero\Twitter\TwitterServiceProvider"
 
$config = '/path/to/configFile.php';
 

return [
    'base_url' => 'https://api.twitter.com/',
    'api_version' => '1.1',
    'api_key' => '',
    'api_secret' => ''
];
 
$cacheMinutes = 30;
 
$tweets = $twitter->getTweetsFromUser($username);

echo $tweets; //=> Print the JSON
$json = $tweets->getBody(); //=> Returns the JSON
$array = $tweets->toArray(); //=> Convert JSON to an array
 
foreach ($tweets as $tweet)
{
    $user = $tweet->user();
    $tweetOwner = $user->getName();
    $tweetUsername = $user->getUsername();
    $tweetText = $tweet->getText();
    $tweetDate = $tweet->getCreatedAt();
}