コード例 #1
0
 public function getUserInfo(SammyK\LaravelFacebookSdk\LaravelFacebookSdk $fb)
 {
     try {
         $response = $fb->get('/me?fields=id,name,email');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Convert the response to a `Facebook/GraphNodes/GraphUser` collection
     $facebook_user = $response->getGraphUser();
     // Create the user if it does not exist or update the existing entry.
     // This will only work if you've added the SyncableGraphNodeTrait to your User model.
     $user = App\User::createOrUpdateGraphNode($facebook_user);
     // Log the user into Laravel
     Auth::login($user);
 }
コード例 #2
0
        dd($helper->getError(), $helper->getErrorCode(), $helper->getErrorReason(), $helper->getErrorDescription());
    }
    if (!$token->isLongLived()) {
        // OAuth 2.0 client handler
        $oauth_client = $fb->getOAuth2Client();
        // Extend the access token.
        try {
            $token = $oauth_client->getLongLivedAccessToken($token);
        } catch (Facebook\Exceptions\FacebookSDKException $e) {
            dd($e->getMessage());
        }
    }
    $fb->setDefaultAccessToken($token);
    // Save for later
    Session::put('fb_user_access_token', (string) $token);
    // Get basic info on the user from Facebook.
    try {
        $response = $fb->get('/me?fields=id,name,email');
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        dd($e->getMessage());
    }
    // Convert the response to a `Facebook/GraphNodes/GraphUser` collection
    $facebook_user = $response->getGraphUser();
    // Create the user if it does not exist or update the existing entry.
    // This will only work if you've added the SyncableGraphNodeTrait to your User model.
    $user = App\User::createOrUpdateGraphNode($facebook_user);
    // Log the user into Laravel
    Auth::login($user);
    return redirect('build')->with('message', 'Successfully logged in with Facebook');
    // return Session::get('fb_user_access_token');
});