Coinbase API: Invalid signature with PHP code

one text

I can not get the Coinbase base API to work because of this error:

{"errors":[{"id":"authentication_error","message":"invalid signature"}]}

I checked multiple times the code, and everything looks correct in relation to the official docs at https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-key-authentication, still, I get the error, this is the code:

 $ch = curl_init('https://api.coinbase.com/v2/user');
 $request_path =  '/v2/user';
 $body = '';
 $time = json_decode(file_get_contents('https://api.coinbase.com/v2/time'), true)['data']['epoch'];
 $signature = $time . 'GET' . $request_path . json_encode($body);
 $signature = hash_hmac('sha256', $signature, 'xxxxxxx');
 $headers = ['Content-Type: application/json',
                     'CB-ACCESS-KEY: xxxxx',
                     'CB-ACCESS-SIGN: ' . $signature,
                     'CB-ACCESS-TIMESTAMP:' . $time,
                     'CB-VERSION: 2017-05-24',
                ];
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 echo curl_exec($ch);

Source