colonel
@colonel
Разработчик PHP, Laravel

Как распарсить $response->getBody()->getContents(), полученный из GuzzleHttp/Client?

Всем привет!
Получаю ответ от сервера Github вот так:
$guzzleClient = new \GuzzleHttp\Client();
                $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'),
                        ]
                    ]
                );

                dd($data->getBody()->getContents());


В итоге имею такую строку:
"error=bad_refresh_token&error_description=The+refresh+token+passed+is+incorrect+or+expired.&error_uri=https%3A%2F%2Fdocs.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-oauth-app-access-token-request-errors%2F%23bad-verification-code"


Как мне её распарсить?
  • Вопрос задан
  • 367 просмотров
Решения вопроса 2
alexey-m-ukolov
@alexey-m-ukolov Куратор тега PHP
By default, the response takes the following form:
access_token=e72e16c7e42f292c6912e7710c838347ae178b4a&token_type=bearer


You can also receive the content in different formats depending on the Accept header:
Accept: application/json
{"access_token":"e72e16c7e42f292c6912e7710c838347ae178b4a", "scope":"repo,gist", "token_type":"bearer"}

Accept: application/xml
<OAuth>
  <token_type>bearer</token_type>
  <scope>repo,gist</scope>
  <access_token>e72e16c7e42f292c6912e7710c838347ae178b4a</access_token>
</OAuth>

https://docs.github.com/en/developers/apps/authori...
Ответ написан
Комментировать
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
ИТЦ Аусферр Магнитогорск
от 100 000 до 160 000 ₽