G
G
Gleb Starkov2021-01-27 12:18:28
PHP
Gleb Starkov, 2021-01-27 12:18:28

POST request to github returns 500 error, what's the problem?

Hello!
I request data to update the token from Github like this:

$data = $guzzleClient->post(
                    'https://github.com/login/oauth/access_token',
                    [
                        'form_params' => [
                            'refresh_token' => $user->github_refresh_token,
                            'grant_type' => 'refresh_token',
                            'client_id' => config('services.github.client_id'),
                            'client_secret' => config('services.github.client_secret'),
                        ]
                    ]
                );


On the local server everything works fine, but on the test server this error:
Server error: `POST https://github.com/login/oauth/access_token` resulted in a `500 Internal Server Error`


That is, the error is on the Github side.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gleb Starkov, 2021-01-27
@colonel

It ended up being solved like this:

$guzzleClient = new \GuzzleHttp\Client([
                    'headers' => [
                        'Content-Type' => 'application/json'
                    ]
                ]);
                $data = $guzzleClient->post(
                    'https://github.com/login/oauth/access_token',
                    [
                        'json' => [
                            'refresh_token' => $user->github_refresh_token,
                            'grant_type' => 'refresh_token',
                            'client_id' => config('services.github.client_id'),
                            'client_secret' => config('services.github.client_secret'),
                        ],
                        'http_errors' => false
                    ]
                );

A
Anton, 2021-01-27
@sHinE

Guzzle has the ability to throw exceptions in case of errors - https://docs.guzzlephp.org/en/stable/quickstart.ht... - some types of exceptions have the ability to look at the server response. Wangyu that github in the answer writes in more detail what is wrong with your request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question