【问题标题】:artdarek oAuth Facebook doesn't workartdarek oAuth Facebook 不起作用
【发布时间】:2017-07-19 22:11:15
【问题描述】:

我的代码如下:

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 );
    }

}

错误:重定向上不存在方法 [getData]。

在调用 http://localhost:8000/v1/facebook 时它总是会带来这个错误,即使我在有效的 OAuth 重定向 URI 中添加了 url 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;

这个过滤器产生了问题,我们可以解决什么问题

【问题讨论】:

    标签: php facebook laravel oauth


    【解决方案1】:

    只需要更新json格式的响应就可以了

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 虽然理论上这可以回答这个问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。
      猜你喜欢
      • 2014-10-17
      • 2014-11-02
      • 2012-11-06
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 2011-07-30
      相关资源
      最近更新 更多