本文介绍了Laravel Passport API调用代码参数为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Laravel客户端调用Laravel API.

I'm trying to call a Laravel API using a Laravel Client.

以下是代码:

Route::get('/callback', function (Request $request) {
    $http = new GuzzleHttp\Client;

    $response = $http->post('http://galaxy.dev/oauth/token', [
        'form_params' => [
            'grant_type' => 'authorization_code',
            'client_id' => '3',
            'client_secret' => 'rrhaEv0B6NAFLyMFqvZrY87gkquFF2UwhAHPtd8L',
            'redirect_uri' => 'http://galaxy-game.dev/callback',
            'code' => $request->code,
        ],
    ]);
    return json_decode((string) $response->getBody(), true);
});

我从API得到以下响应:

我在API错误日志中注意到了这一点:

有人知道为什么会这样吗?这似乎是失败的原因.我完全遵循了Laravel文档.任何帮助将不胜感激!

Does anyone have any ideas why this might be? This seems to be the reason why it is failing. I have followed the Laravel docs exactly. Any help would be greatly appreciated!

推荐答案

我通过将代码值保留为空来解决了这个问题,

Hi I fixed this by leaving the code value empty like this:

'code' => '',

由于$request->codenull,可能会导致该问题.

Since $request->code is null, that probably causes that problem.

这篇关于Laravel Passport API调用代码参数为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:25
查看更多