401 Bad Credential While Downloading a Recording
nabinem opened this issue · 2 comments
I upgraded sdk from 3.x to latest version 4.0.x and now downloading recording no longer works which use to work on 3.x
Current Behavior
I am getting 401 Bad Credential
$data->getStatusCode(); is returning 401 instead of 200
Steps to Reproduce (for bugs)
$basic = new \Vonage\Client\Credentials\Basic('key', 'secret');
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic, $keypair));
$data = $client->get($recordingUrl);
file_put_contents($recordingId.'.mp3', $data->getBody());
$data->getStatusCode(); is returning 401 instead of 200
Your Environment
- Version used: 4.0.10
- PHP 8.0 on nginx
I think I've finally spotted what the problem is here.
You're using the get
on the Client directly rather than the Voice Client. The individual clients are configured with APIResource objects that have AuthHandler configurations. I'll make a note to get some nice pass-through methods, but for the time being you can pull out the APIResource
which will handle the auth for you:
$data = $client->voice()->getApiResource()->get($recordingUrl);
Ticket put in Vonage workload to add $client->voice()->getRecording($url)
syntax