Last active
March 28, 2017 23:20
-
-
Save jmarreros/3914905709fb0ef5dfd055f51c9a50ca to your computer and use it in GitHub Desktop.
Conexión y Validación de errores para la REST API Woocommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use Automattic\WooCommerce\Client; | |
use Automattic\WooCommerce\HttpClient\HttpClientException; | |
try { | |
$woocommerce = new Client( | |
'http://tusitio.com/', | |
'ck_xxx', | |
'cs_xxx', | |
[ | |
'wp_api' => true, | |
'version' => 'wc/v1', | |
] | |
); | |
print_r($woocommerce->get('products')); | |
} catch (HttpClientException $e) { | |
\print_r($e); | |
\print_r($e->getMessage() . PHP_EOL); | |
\print_r('Code: ' . $e->getResponse()->getCode() . PHP_EOL); | |
\print_r('Body: ' . $e->getResponse()->getBody() . PHP_EOL); | |
} | |
$e->getResponse()->getBody(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment