7

Laravel Socialite では、facebook にリダイレクトされます。しかし、ユーザーがキャンセルすると (Facebook がパブリック プロファイルにアクセスできないようにする)、Missing Authorization 例外というエラーが発生します。

RequestException.php 行 107 の ClientException: クライアント エラー: GET https://graph.facebook.com/oauth/access_token?client_id=1309844325833234&client_secret=1304bbdd28400tret49a295d324d577c&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fauth%2Ffacebook%2Fcallbackが発生しました400 Bad Request 応答: {"error":{"message":"Missing authentication code","type":"OAuthException","code":1,"fbtrace_id":"Aq9wMwG6ewl"}}

これを表示したくない代わりに、スタックオーバーフローのFacebookログインに表示されるような「Facebookログインに失敗しました」というメッセージを表示して、サイトのホームページに戻りたいです。

4

2 に答える 2

6

ようやく答えが出ました。

public function handleProviderCallback()
{
    try {
        $user = Socialite::driver('facebook')->user();
    } catch (\Exception $e) {
        //Here you can write excepion Handling Logic
    }
}
于 2016-04-06T01:19:34.123 に答える
1

Try catch didn't give good result to me. I used below methods to catch this error. If you're using Laravel Socialite library definitely it has function call handleProviderCallback. In that use this code

handleProviderCallback Method

/**
 * Obtain the user information from GitHub.
 *
 * @return Response
 */
public function handleProviderCallback()
{

    $error_code = Input::get('error_code');

    if ($error_code == 200)
    {
        return redirect()->route('sign-in')->with('error','You\'ve chose not to grant us permission to connect with your Facebook account.');
    }
    else
    {
        $fbUser = Socialite::driver('facebook')->user();
        # rest of your code
    }
}

Where does this error_code come from ??

Well, If you look at the error page(Laravel Black screened) come to you check the URL of that page. It has the these get methods error , error_code , error_description , error_reason , state.

Ex : http://localhost:8000/login/facebook/callback?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=mIxNjoDCogT2piMV5LX1Imk6GWNzqPUt3JZaqsIo#_=_


What I can do this to optimize this

You can use a switch statement based on error Check this Facebook error codes, with an error message and pass it.

于 2017-10-19T07:34:09.557 に答える