rbadillap/twitterstreaming-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rbadillap/twitterstreaming-laravel

Composer 安装命令:

composer require rbadillap/twitterstreaming-laravel

包简介

TwitterStreaming Service Provider for Laravel

README 文档

README

We are now supporting TwitterStreamingPHP with Laravel 5 through a Service Provider :)

Installation

This TwitterStreamingPHP Service Provider can be installed via Composer. Running the following command:

composer require rbadillap/twitterstreaming-laravel

Now you should register the provider in the Laravel application in your config/app.php configuration file:

'providers' => [
	// other service providers..
		
    TwitterStreaming\Laravel\TwitterStreamingServiceProvider::class
],

Also, add the TwitterStreaming facade in the aliasses array (located in the same file).

'TwitterStreaming' => TwitterStreaming\Laravel\Facades\TwitterStreaming::class

Also you may want to create a twitterstreaming.php configuration file, to do that and put on it the credentials of your Twitter App you should run the following command:

php artisan vendor:publish

Now, you can see a new file created in the app folder where you can add your credentials.

And ready to use!

Usage

To understand how to use TwitterStreamingPHP please visit its documentation

Extras

Within this Service Package you will find some extra methods to simplify the way to work with TwitterStreamingPHP in Laravel. Let's take a look all of them:

Simplified way to define the endpoints

Instead of define the endpoints using the endpoint method in TwitterStreamingPHP you can call some methods which injects the endpoint (and its types) directly. For example:

// Instead of
(new Tracker)
    ->endpoint(Endpoints\PublicEndpoint::class, 'sample')

// You can call in Laravel
TwitterStreaming::publicSample()

// and continue with the rest of the code

All the methods to simplify the endpoints definitions listed here:

publicFilter()
// alias of endpoint(Endpoints\PublicEndpoint::class, 'filter')
publicSample()
// alias of endpoint(Endpoints\PublicEndpoint::class, 'sample')
user()
// alias of endpoint(Endpoints\UserEndpoint::class)

Integration with Filters module

Are you using Filters module?

If no, well, you should :)

If yes, we have been integrated into the Laravel Service Provider.

The only thing that you need to use is require the package using composer:

composer require rbadillap/twitterstreaming-filters

And use it without the need to register the new extension.

// this is not necessary
->addExtension(Extensions\Filters::class)

// TwitterStreamingPHP detects automatically if the module are included with composer 
// and you can use filters method automatically

    ->filters(function ($filters) {
        return $filters
            // Use methods to filter tweets
            ->withoutRTs()
            ->withoutReplies()
            ->onlyFromAndroid();
    })

How can I use it in Laravel

There is some ways, but if you wanna combine Laravel and TwitterStreamingPHP you can create your own command

php artisan make:console TwitterTrack

And put your logic to track tweets.

        TwitterStreaming::publicFilter()
            ->parameters([
                'track' => '#realmadrid'
            ])
            ->filters(function ($filters) {
                return $filters
                    ->withoutRTs()
                    ->withoutReplies()
                    ->onlyFromAndroid();
            })
            ->track(function ($tweet) {
                print $tweet->text . ' (' . $tweet->source . ')' . PHP_EOL . PHP_EOL;
            });

Even better, you could dispatch a queue listener to store in database.

        TwitterStreaming::publicFilter()
            ->parameters([
                'track' => '#realmadrid'
            ])
            ->filters(function ($filters) {
                return $filters
                    ->withoutRTs()
                    ->withoutReplies()
                    ->onlyFromAndroid();
            })
            ->track(function ($tweet) {
                // php artisan make:job YourLaravelJob
                $this->dispatch(new YourLaravelJob($tweet));
            });

Contributing

Use the same workflow as many of the packages that we have here in Github.

  1. Fork the project.
  2. Create your feature branch with a related-issue name.
  3. Try to be clear with the code committed and follow the PSR-2 Coding Style Guide.
  4. Run the tests (and create your new ones if necessary).
  5. Commit and push the branch.
  6. Create the Pull Request.

统计信息

  • 总下载量: 332
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固