floriantraun/laratweet

Provides a simple solution to access the twitter API easily.

v1.2.0 2017-11-25 20:17 UTC

This package is auto-updated.

Last update: 2022-04-29 01:14:27 UTC


README

Provides a simple solution to access the Twitter API easily.

Installation

Installation is straightforward, setup is similar to every other Laravel Package.

1. Install via Composer

Begin by pulling in the package through Composer:

composer require floriantraun/laratweet

2. Define the Service Provider and alias

Next we need to pull in the alias and service providers.

Note: This package supports the new auto-discovery features of Laravel 5.5, so if you are working on a Laravel 5.5+ project, then your install is complete, you can skip to step 3.

Inside of your config/app.php define a new service provider

'providers' => [
	//  other providers

	FlorianTraun\LaraTweet\LaraTweetServiceProvider::class,
];

Then we want to define an alias in the same config/app.php file.

'aliases' => [
	// other aliases

	'LaraTweet' => FlorianTraun\LaraTweet\LaraTweetFacade::class,
];

3. Publish Config File

The config file allows you to override default settings of this package to meet your specific needs.

To generate a config file type this command into your terminal:

php artisan vendor:publish --tag=laratweet

4. Setting Your Keys

Add the following to your .env file:

TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=

Usage

In order to get a file URL, you need to use LaraTweet;. Afterwards you can use the LaraTweet functions as described in "Available Methods" below.

use LaraTweet;

class PageController extends Controller
{
	public function index()
	{
		$tweets = LaraTweet::getUserTimeline(['screen_name' => 'floriantraun', 'count' => '3']);
	}
}

Available Methods

$parameters are always an array with parameters according to https://developer.twitter.com/en/docs.

  • LaraTweet::getStatus($parameters): Returns a single Tweet, specified by the id parameter. The Tweet’s author will also be embedded within the Tweet.
  • LaraTweet::getSearch($parameters): Returns a collection of relevant Tweets matching a specified query.
  • LaraTweet::getUserTimeline($parameters): Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_idw parameters.
  • LaraTweet::linkify($tweet): Wraps links inside a anchor tag ($tweet must be a Twitter API object).

Helper Function

Instead of calling LaraTweet::method(), you can use the helper function laratweet(). You can use it as an alias for the class like this: laratweet()->getUserTimeline($parameters)

Contribute

I encourage you to contribute to this package to improve it and make it better. Even if you don't feel comfortable with coding or submitting a pull-request (PR), you can still support it by submitting issues with bugs or requesting new features, or simply helping discuss existing issues to give us your opinion and shape the progress of this package.

Read the full Contribution Guide

Contact

I would love to hear from you.

I am always on Twitter, and it is a great way to communicate with me or follow me. Check me out on Twitter.

You can also email me at flo@floriantraun.at for any other requests.