更新时间:2023-01-10 16:19:17
使用Twitter时,Twitter处理的重定向URL将发送两个查询参数 oauth_token 和 oauth_verifier .
When working with twitter, redirect URL handled by twitter will send two query parameters oauth_token and oauth_verifier.
因此,您可以添加路由验证以检查URL是否包含参数.
So you can add route validation to check that the URL contains the parameters.
在控制器中添加验证
public function yourcallbackfunction()
{
$v = \Validator::make(request()->all(), [
'oauth_token' => 'required',
'oauth_verifier' => 'required'
];
if($v->fails()) {
//do something as it's not a valid twitter callback
}else {
$user = Socialite::driver('twitter')->user();
}
}
***在try catch中处理社交名流调用,以捕获社交名流可能引发的其他错误,例如无效令牌错误或api上的通信错误.
It's better to handle the socialite call within a try catch to catch other errors that might be thrown by the socialite like invalid token errors or communication error on api.