Webアプリ習作#5

前記事に引き続き主にこちらを参考にしました。
Laravel Socialiteを使ってTwitterアカウントでログイン機能 - Crieit

ログイン処理の実装

プロジェクトディレクトリで以下を実行

php artisan make:controller TwitterAuthController

\app\Http\Controllers\TwitterAuthController.phpが生成されるので、これを開いて以下のように編集

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Socialite;

class TwitterAuthController extends Controller
{
    public function login()
    {
        return Socialite::with('Twitter')->redirect();
    }

    public function callback()
    {
        $user = Socialite::driver('Twitter')->user();
        dd($user);
    }
}

routes/web.phpにルーティングを追加

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});
// ここからを追加.
Route::prefix('auth')->group(function () {
    Route::get('twitter', 'TwitterAuthController@login');
    Route::get('twitter/callback', 'TwitterAuthController@callback');
});
// ここまでを追加.
動作確認

ローカルサーバを起動して下記にアクセス
http://localhost:8000/auth/twitter

Twitterのアプリ認証画面にリダイレクトするので[連携アプリを認証]をクリック

※エラー発生※
認証後にアプリに戻ってきたタイミングでエラーが発生する

Exception
Received error [{"errors":[{"message":"You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve","code":453}]} ] with status code [403] when retrieving token credentials.

対象のプロジェクトがEssential accessなのでTwitter API v2のエンドポイントしか使えないとのこと
新しい開発者プラットフォームでTwitterの未来を構築
Getting Started with the Twitter API | Docs | Twitter Developer Platform

この問題を解決するにはAPI v1.1を使わないようにするか、あるいは申請してアクセスレベルをelavatedにする必要がある