Sms & Fax-old - Comment utiliser l'API OVH INVALID_CREDENTIAL ou NOT_GRANTED_CALL
... / Comment utiliser l'API OV...
BMPCreated with Sketch.BMPZIPCreated with Sketch.ZIPXLSCreated with Sketch.XLSTXTCreated with Sketch.TXTPPTCreated with Sketch.PPTPNGCreated with Sketch.PNGPDFCreated with Sketch.PDFJPGCreated with Sketch.JPGGIFCreated with Sketch.GIFDOCCreated with Sketch.DOC Error Created with Sketch.
Frage

Comment utiliser l'API OVH INVALID_CREDENTIAL ou NOT_GRANTED_CALL

Von
AlainB17
Erstellungsdatum 2018-11-26 08:36:05 (edited on 2024-09-04 13:06:47) in Sms & Fax-old

Bonjour,

Je tente d'utiliser l'API OVH pour envoyer des SMS et je me base sur cette page.

J'ai donc d'abord créé ma consumer key ici en utilisant ces infos:

GET : /sms/
GET: /sms/sms-lyxxxxxx-1/
POST: /sms/sms-lyxxxxxx-1/
etc...

Je fais juste appel à l'API ainsi:

require __DIR__ . './../vendor/autoload.php';
use \Ovh\Api;

$endpoint = 'ovh-eu';
$applicationKey = "x..........";
$applicationSecret = "X...............";
$consumerKey = "I.......................";



$conn = new Api( $applicationKey,
$applicationSecret,
$endpoint,
$consumerKey);

$smsServices = $conn->get('/sms/');
foreach ($smsServices as $smsService) {

print_r($smsService);
}

Et là je reçois le message suivant:

PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://api.ovh.com/1.0/sms/` resulted in a `403 Forbidden` response:
{"errorCode":"NOT_GRANTED_CALL","message":"This call has not been granted","httpCode":"403 Forbidden"}
in /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /var/www/depot/Serveur/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /var/www/depot/Serveur/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /var/www/depot/Serveur/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /var/www/depot/Serveur/vendor/guzzlehttp/pr in /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

Pensant que spécifier le compte ne fonctionnait pas franchement bien, j'ai donc essayé comme spécifié dans la page explicative. C'est à dire ainsi:

GET : /sms/
GET: /sms/*
POST: /sms/*
etc...

Et là je reçois le message suivant:

PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://api.ovh.com/1.0/sms/` resulted in a `403 Forbidden` response:
{"httpCode":"403 Forbidden","errorCode":"INVALID_CREDENTIAL","message":"This credential is not valid"}
in /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /var/www/depot/Serveur/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /var/www/depot/Serveur/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /var/www/depot/Serveur/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /var/www/depot/Serveur/vendor/guzzlehttp/pr in /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

J'ai donc tenté avec l'API SMS dispo sur github.
Et j'ai donc créé le petit script php appelant juste le getAccounts().
Idem avec les 2 jeux de clés, je reçois le message:

PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error response [url] https://api.ovh.com/1.0/sms/ [status code] 403 [reason phrase] Forbidden in /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89
Stack trace:
#0 /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(32): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response))
#1 /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(108): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete')
#2 /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent))
#3 /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/RequestFsm.php(132): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))
#4 /var/www/depot/Serveur/vendor/react/promise/src/FulfilledPromise.php(25): GuzzleHttp\RequestFs in /var/www/depot/Serveur/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 89

On dirait bien que j'ai oublié une étape mais quoi?


1 Antwort ( Latest reply on 2020-09-01 21:38:09 Von
FabienL18
)

Bonjour,

Venant de tomber sur l'erreur :
à la ligne
$smsServices = $conn->get('/sms/');
il faut mettre
$smsServices = $conn->get('/sms');

(sans le slash final)