Vonage / vonage-php-sdk-core

Vonage REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
https://developer.vonage.com/
Apache License 2.0
917 stars 181 forks source link

401 Bad Credential While Downloading a Recording #387

Closed nabinem closed 1 year ago

nabinem commented 1 year ago

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

SecondeJK commented 1 year ago

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);
SecondeJK commented 1 year ago

Ticket put in Vonage workload to add $client->voice()->getRecording($url) syntax