-
app/Console/Commands/TwitterGiveaway.php
Open in GitHubuse DG\Twitter\Twitter; use Illuminate\Console\Command; class TwitterGiveaway extends Command { protected Twitter $twitter; // protected function getUser(string $username): array { $user = $this->twitter->request(sprintf('https://api.twitter.com/1.1/users/show.json?screen_name=%s&include_entities=false', $username), 'GET'); return [ 'id' => $user->id, 'name' => $user->name, 'username' => $user->screen_name, 'avatar' => str_replace('_normal', '', $user->profile_image_url_https), ]; } }
-
composer.json
Open in GitHub{ "require": { "php": "^7.4", // "dg/twitter-php": "^4.1" }, }
-
master/app/Providers/TwitterServiceProvider.php
Open in GitHubuse DG\Twitter\Twitter; use Illuminate\Support\ServiceProvider; class TwitterServiceProvider extends ServiceProvider { public function register(): void { $this->app->singleton(Twitter::class, function (): Twitter { return new Twitter( config('services.twitter.consumer_key'), config('services.twitter.consumer_secret'), config('services.twitter.access_token'), config('services.twitter.access_token_secret') ); }); } }
-
config/app.php
Open in GitHubreturn [ // /* * Application Service Providers... */ // App\Providers\TwitterServiceProvider::class, ], // ];