artdarek oAuth Facebook不起作用

时间:2017-07-19 07:13:49

标签: php facebook laravel oauth

我的代码如下:

Route::get('/facebook', 'ApiUserController@socialConnect');

public function socialConnect()
    {

    // get data from input
    $code = Input::get( 'code' );

    // get fb service
    $fb = OAuth::consumer( 'Facebook' );

    // check if code is valid

    // if code is provided get user data and sign in
    if ( !empty( $code ) ) {

        // This was a callback request from facebook, get the token
        $token = $fb->requestAccessToken( $code );

        // Send a request with it
        $result = json_decode( $fb->request( '/me' ), true );

        $message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
        echo $message. "<br/>";

        //Var_dump
        //display whole array().
        dd($result);

    }
    // if not ask for permission first
    else {
        // get fb authorization
        $url = $fb->getAuthorizationUri();

        // return to facebook login url
         return Redirect::to( (string)$url );
    }

}
  

错误:Redirect上不存在方法[getData]。

即使我在有效OAuth重定向URI中添加了网址http://localhost:8000/v1/facebook,它也会在调用http://localhost:8000/v1/facebook时出现此错误

请提出相同的建议

$duration = Benchmarking::end('application');
    $duration = ($duration * 1000) . 'ms';

    Log::info($response->getStatusCode() . ' ' . $request->path() . ' :: ' . $duration);

if (!Config::get('app.debug'))
{
    return $response;
}

$data = $response->getData();

if (is_array($data)) {
    return $response;
}

$data->queryLog = DB::getQueryLog();
$data->responseTime = $duration;

$response->setData($data);

return $response;

这个过滤器会产生问题,我们可以解决它的问题

2 个答案:

答案 0 :(得分:0)

只需要以json格式更新响应就可以正常工作

答案 1 :(得分:0)

社交身份验证有一个非常简单的包:https://github.com/laravel/socialite