Skip to content

Instantly share code, notes, and snippets.

@missoxd
Last active March 13, 2020 17:08
Show Gist options
  • Save missoxd/29fc8a77e159974df1002037b239c5ba to your computer and use it in GitHub Desktop.
Save missoxd/29fc8a77e159974df1002037b239c5ba to your computer and use it in GitHub Desktop.
<?php
/**
* Quando já temos o access_token e o token_secret.
*
* Precisamos ter a OAuth lib instalada no PHP, caso ela não esteja presente, no Ubuntu podemos instalar com:
* $ sudo apt install php-oauth
*/
$url = 'https://<mage-host>/api/rest/';
$consumerKey = '<consumer-key>';
$consumerSecret = '<consumer-secret>';
$token = '<token>';
$tokenSecret = '<token-secret>';
try {
$oauth = new \OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->enableDebug();
$oauth->setToken($token, $tokenSecret);
$resource = $url . 'orders';
$oauth->fetch($resource, [], 'GET', ['Content-Type' => 'application/json', 'Accept' => 'application/json']);
$response = json_decode($oauth->getLastResponse());
print_r($response);
} catch (\OAuthException $e) {
print_r($e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment