在获取临时凭据时收到带有消息“{"errors":[{"code":32,"message":"Could not authenticate you."}]}”的 HTTP 状态代码 [401]
Received HTTP status code [401] with message "{"errors":[{"code":32,"message":"Could not authenticate you."}]}" when getting temporary credentials
我正在使用 laravel/socialite 包。
我正在尝试使用 Twitter 登录 API 但在获取临时凭据时出现此错误:
Received HTTP status code [401] with message "{"errors":[{"code":32,"message":"Could not authenticate you."}]}"
// config/services.php
'twitter' => [
'client_id' => env('TWITTER_APP_API_KEY'),
'client_secret' => env('TWITTER_APP_API_SECRET'),
'redirect' => env('TWITTER_APP_CALLBACK'),
],
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
class SocialController extends Controller
{
public function redirect($provider)
{
return Socialite::driver($provider)->redirect();
}
public function callback($provider)
{
$user = Socialite::driver($provider)->user();
return (array)$user;
}
}
// routes/web.php
Route::get('/redirect/{provider}', [SocialController::class, 'redirect']);
Route::get('{provider}/callback', [SocialController::class, 'callback']);
// .env
TWITTER_APP_API_KEY=MY_TWITTER_APP_API_KEY
TWITTER_APP_API_SECRET=MY_TWITTER_APP_API_SECRET
TWITTER_APP_CALLBACK=http://mywebsite.test/twitter/callback
我在阅读 laravel/socailite 文档后解决了问题
我不需要添加以下代码
//config/app.php
....
....
'providers' => [
....
....
Laravel\Socialite\SocialiteServiceProvider::class,
],
'aliases' => [
....
....
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
],
....
....
我需要做的一切
composer require laravel/socialite
然后进行以下步骤:
# install
composer require socialiteproviders/twitter
# register
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
'SocialiteProviders\Twitter\TwitterExtendSocialite@handle'
],
];
# configure
'twitter' => [
'client_id' => env('TWITTER_KEY'),
'client_secret' => env('TWITTER_SECRET'),
'redirect' => env('TWITTER_REDIRECT_URI'),
]
# start building
return Socialite::driver('twitter')->redirect();
您可以在此处安装任何社交名流提供者表格:https://socialiteproviders.com/
我正在使用 laravel/socialite 包。
我正在尝试使用 Twitter 登录 API 但在获取临时凭据时出现此错误:
Received HTTP status code [401] with message "{"errors":[{"code":32,"message":"Could not authenticate you."}]}"
// config/services.php
'twitter' => [
'client_id' => env('TWITTER_APP_API_KEY'),
'client_secret' => env('TWITTER_APP_API_SECRET'),
'redirect' => env('TWITTER_APP_CALLBACK'),
],
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
class SocialController extends Controller
{
public function redirect($provider)
{
return Socialite::driver($provider)->redirect();
}
public function callback($provider)
{
$user = Socialite::driver($provider)->user();
return (array)$user;
}
}
// routes/web.php
Route::get('/redirect/{provider}', [SocialController::class, 'redirect']);
Route::get('{provider}/callback', [SocialController::class, 'callback']);
// .env
TWITTER_APP_API_KEY=MY_TWITTER_APP_API_KEY
TWITTER_APP_API_SECRET=MY_TWITTER_APP_API_SECRET
TWITTER_APP_CALLBACK=http://mywebsite.test/twitter/callback
我在阅读 laravel/socailite 文档后解决了问题
我不需要添加以下代码
//config/app.php
....
....
'providers' => [
....
....
Laravel\Socialite\SocialiteServiceProvider::class,
],
'aliases' => [
....
....
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
],
....
....
我需要做的一切
composer require laravel/socialite
然后进行以下步骤:
# install
composer require socialiteproviders/twitter
# register
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
'SocialiteProviders\Twitter\TwitterExtendSocialite@handle'
],
];
# configure
'twitter' => [
'client_id' => env('TWITTER_KEY'),
'client_secret' => env('TWITTER_SECRET'),
'redirect' => env('TWITTER_REDIRECT_URI'),
]
# start building
return Socialite::driver('twitter')->redirect();
您可以在此处安装任何社交名流提供者表格:https://socialiteproviders.com/