I\'m trying to connect to the WooCommerce API using Guzzle 5 (Guzzle 6 seems not has oAuth options o.O). Woocommerce requires the oAuth authentication method to work.
<
Updating @Aerendir answer
In his pull request, @Aerendir wrote:
In my case, I did the editing as I were trying to connect to the WooCommerce API version 2 but that version of the API didn't implement correctly the OAuth Core 1.0a spec. In fact, they fixed this issue in the version 3 of the API. See Differences between V3 and older versions.
source: https://github.com/guzzle/oauth-subscriber/pull/42#issuecomment-185631670
So, to make his answer work properly, we need to use wc-api/v3/ instead of wc-api/v2/.
The following code, works using Guzzle 6, oauth and WooCommerce api v3:
use GuzzleHttp\Client,
GuzzleHttp\HandlerStack,
GuzzleHttp\Handler\CurlHandler,
GuzzleHttp\Subscriber\Oauth\Oauth1;
$url = 'http://localhost/WooCommerce/';
$api = 'wc-api/v3/';
$endpoint = 'orders';
$consumer_key = 'ck_999ffa6b1be3f38058ed83e5786ac133e8c0bc60';
$consumer_secret = 'cs_8f6c96c56a7281203c2ff35d71e5c4f9b70e9704';
$handler = new CurlHandler();
$stack = HandlerStack::create($handler);
$middleware = new Oauth1([
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'token_secret' => '',
'token' => '',
'request_method' => Oauth1::REQUEST_METHOD_QUERY,
'signature_method' => Oauth1::SIGNATURE_METHOD_HMAC
]);
$stack->push($middleware);
$client = new Client([
'base_uri' => $url . $api,
'handler' => $stack
]);
$response = $client->get( $endpoint, [ 'auth' => 'oauth' ] );
echo $response->getStatusCode() . '
';
echo $response->getHeaderLine('content-type') . '
';
echo $response->getBody();