Connection

The Twitter extension comes with a pre-configured connection class to use for making API calls to Twitter's v1.1 API.

Configuring

Before you can leverage this extension you need to head to Settings > Extensions > Twitter Extension and enter your API credentials from https://developer.twitter.com/en/apps.

Getting Started

To get started you will need to resolve or inject the connection class into your code. The connection class will already be configured to your authentication settings. Below is an example of a basic Laravel command:

<?php namespace Anomaly\ExampleTheme\Command;

use Abraham\TwitterOAuth\TwitterOAuth;
use Anomaly\TwitterExtension\Twitter\TwitterConnection;

class GetRecentTweets
{

    public function handle(TwitterConnection $connection)
    {
    
        /* @var TwitterOAuth $connection */
        $recent = $connection->get(
            'statuses/user_timeline',
            [
                'screen_name' => 'pyrocms',
                'include_rts' => false,
                'count'       => 10,
            ]
        );

        return $recent;
    }
}

Notice how the $connection is hinted as the TwitterOAuth class. This is because it's a wrapper for it. If you need to get the literal TwitterOAuth instance for any reason you can use getConnection:

$real = $connection->getConnection();

TwitterOAuth Documentation

For more information on available functionality please refer to the documentation for the package: https://twitteroauth.com/