Skip to main content
Clarification
Source Link

On getBodyUnpack response content with $response->getBody(), I needed to run getContents->getContents(), like:.

echouse GuzzleHttp\Client;

Route::get('/approve', function () {
    header('Location: https://stackexchange.com/oauth?client_id=12345&scope=write_access&redirect_uri=https://mysite.com/approved');
});

Route::get('/approved', function (Request $request) {
    $client = new Client();    
    $response = $client->request('POST', 'https://stackexchange.com/oauth/access_token/json', [
        'form_params' => [
            'client_id' => 12345,
            'client_secret' => 'apfeusenfpuansefpunapfn((',
            'code' => \Request::get("code"),
            'redirect_uri' => 'https://mysite.com/approved'
        ]
    ]);

    dd($response->getBody()->getContents());
    // {"access_token":"sdoginGDpng3pnGPNGDDGGDP))","expires":86399}
});

On getBody(), I needed to run getContents(), like:

echo $response->getBody()->getContents()
// {"access_token":"sdoginGDpng3pnGPNGDDGGDP))","expires":86399}

Unpack response content with $response->getBody()->getContents().

use GuzzleHttp\Client;

Route::get('/approve', function () {
    header('Location: https://stackexchange.com/oauth?client_id=12345&scope=write_access&redirect_uri=https://mysite.com/approved');
});

Route::get('/approved', function (Request $request) {
    $client = new Client();    
    $response = $client->request('POST', 'https://stackexchange.com/oauth/access_token/json', [
        'form_params' => [
            'client_id' => 12345,
            'client_secret' => 'apfeusenfpuansefpunapfn((',
            'code' => \Request::get("code"),
            'redirect_uri' => 'https://mysite.com/approved'
        ]
    ]);

    dd($response->getBody()->getContents());
    // {"access_token":"sdoginGDpng3pnGPNGDDGGDP))","expires":86399}
});
Source Link

On getBody(), I needed to run getContents(), like:

echo $response->getBody()->getContents()
// {"access_token":"sdoginGDpng3pnGPNGDDGGDP))","expires":86399}