Laravel Socialite Facebook 错误:“POST https://graph.facebook.c

2023-07-16php开发问题
3

本文介绍了Laravel Socialite Facebook 错误:“POST https://graph.facebook.com/oauth/access_token 导致‘400 错误请求’"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经使用 Laravel Socialite 为 Facebook 进行了社交登录,并且运行良好.我没有改变任何东西,现在它不起作用.尝试登录时显示此错误:

I've made social login using Laravel Socialite for facebook and it was working fine. I haaven't changed anything and now it's not working. It shows this error when trying to login:

客户端错误:POST https://graph.facebook.com/oauth/access_token导致400 Bad Request响应:{"error":{"message":"此 IP 无法向该应用程序发出请求.","type":"OAuthException","code":5,"fbtrace_id":"D(已截断...)

Client error:POST https://graph.facebook.com/oauth/access_tokenresulted in a400 Bad Requestresponse: {"error":{"message":"This IP can't make requests for that application.","type":"OAuthException","code":5,"fbtrace_id":"D (truncated...)

我没有更改 Facebook 应用程序中的设置,也没有更改我的代码.我的代码如下:

I haven't changed setting in my facebook app, nor in my code. My code is the following:

Route::get('login', ['as' =>'getLogin', 'uses'=>'AuthAuthController@getLogin']);
Route::get('handleProviderCallback/{provider}', 'AuthAuthController@handleProviderCallback');

public function login($provider = false)
    {
     if(!$provider) {
            $user = Input::all();
            $auth_user = new AuthenticateUser();
            $is_logged = $auth_user->findByEmailOrCreate($user, false);
            if($is_logged) {

                Session::put('user', Auth::user());
                Session::put('user_id', Auth::user()->id);
                Session::put('email', Auth::user()->email);
                Session::put('name', Auth::user()->name);

                return redirect()->intended('dashboard');
            }
            return redirect('/')->withInput()->with('error', 'Wrong username or password!');
        }
        return Socialite::with('facebook')->redirect();
    }
    
    public function handleProviderCallback($provider=false) {
        if(Input::has('code')) {
            $user = Socialite::with($provider)->user();
            $auth_user = new AuthenticateUser();
            $provider_user = $auth_user->findByEmailOrCreate($user, $provider);
            Session::put("user", array($provider_user));
            Session::put('user_id', $provider_user->id);
            Session::put('email',$provider_user->email);
            Session::put('name',$provider_user->name);

            return redirect('dashboard');
        }
    }

问题出现在这一行的 handleProviderCallback 方法中:

Problem appears in handleProviderCallback method in this line:

$user = Socialite::with($provider)->user();.

当我只转储这个时:$user = Socialite::with($provider)

它显示数据,但是当它像这样用来获取用户数据时,它返回错误:

it shows data but when it is used like that to get user data it returns the error:

$user = Socialite::with($provider)->user();

config/services.php 中,我设置了如下示例:

In config/services.php I've set settings like this example:

  'facebook' => [
        'client_id' => 'my-client-id-from-fb-app', 
        'client_secret' => 'my-secret-code-from-fb-app', 
        'redirect' => 'http://my-example-domain/my-site/handleProviderCallback/facebook'
    ],

在我的 facebook 应用程序中,我在设置中进行了设置:

In my facebook app I've set in settings:

应用域:my-example-domain,隐私政策网址:http://my-example-domain/my-site/,网站网址:http://my-example-domain/my-site/handleProviderCallback/facebook,有效的 OAuth 重定向 URI:http://my-example-domain/my-site/handleProviderCallback/facebook

推荐答案

是的,我根本没有检查请求以查看返回的内容,但是 Larachat 上有人帮我解决了这个问题.

Yeah, I didn't check the request at all to see what's returned but someone on Larachat helped me solve this problem.

在获取用户并处理请求之前,我所要做的就是在回调方法中添加以下代码:

All I had to do before getting the user and handle the request was to add the following code in the callback method:

if (!$request->has('code') || $request->has('denied')) {
   return redirect('/');}

这篇关于Laravel Socialite Facebook 错误:“POST https://graph.facebook.com/oauth/access_token 导致‘400 错误请求’"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17