2

伙计们,我正在尝试访问用户的个人信息。我正在使用 Facebook-sdk Laravel Bundle。事情是...

<?php

class App_Controller extends Base_Controller {

    public $restful = true;    

    public function get_check()
    {
        // Chequeo que el FbId haya puesto Like en la pagina
        $facebook = IoC::resolve('facebook-sdk');

        $accessToken = $facebook->getAccessToken();
        $user = $facebook->getUser();

        if ($user) {
            try {
                // Proceed knowing you have a logged in user who's authenticated.
                $user_profile = $facebook->api('/me');
            } catch (FacebookApiException $e) {
                error_log($e);
                $user = null;
            }
        }else{
            $params = array(
                'scope' => 'read_stream, friends_likes',
                'redirect_uri' => 'http://someurl.com' // I've removed the actual url 
            );
            $login_url = $facebook->getLoginUrl($params);
            //return Response::make( '', 302 )->header( 'Location', $login_url );
        }

        echo $user;
    }    

    public function get_game()
    {
        // Imprimo la pantalla del juego
        return View::make('game');
    }    

    /*public function get_logout(){
        $facebook = IoC::resolve('facebook-sdk');
        $user = $facebook->getUser();

        $params = array(
            'scope' => 'read_stream, friends_likes',
            'redirect_uri' => 'http://www.conamor.org/apps/aventuracenter/pacman/public/game/'
        );
        if($user){
            $url = $facebook->getLogoutUrl();
        }else{
            $url = $facebook->getLoginUrl();
        }

        header("Location: ".$url); 
    }*/

}

所以,当我回显 $user 时,我只得到 0 作为它的值,而不是一个对象。任何想法?

谢谢!

4

1 回答 1

2

就在这个周末,我一直在玩 fb 登录,并得到了这个工作:

Route::get('/', function()
{
    $facebook = IoC::resolve('facebook-sdk');

    $params = array(
      'scope' => 'email',
      'redirect_uri' => 'http://www.yoururl.com'
    );

    $loginUrl = $facebook->getLoginUrl($params);

    $uid = $facebook->getUser();

    if($uid)
    {
        $user_profile = $facebook->api('/me');
        var_dump($user_profile);
    }else{
        return View::make('home.index') ->with('facebook_login', $loginUrl);
    }                               
});

在我看来,我使用 {{ HTML::link($facebook_login, 'login') }} 进行登录。你应该可以在我上面的代码中添加错误异常,我当时没有打扰,因为它只是为了测试;)

注销我使用它,因为 getLogoutUrl 无法为我注销:

Route::get('logout', function()
{
    $facebook = IoC::resolve('facebook-sdk');
    $facebook->destroySession();
    return Redirect::to('/');
});
于 2013-05-06T22:00:24.953 回答