php - services - Obtenga un feed de producto magento usando la api de reposo de Mangento, pero el error de OAuth
magento login api (1)
Tengo un sitio web core php donde el cliente crea un tipo diferente de widgets para obtener informes en forma de gráficos. Quiero desarrollar un widget para ese fin para mostrar los pedidos de Magento informes, informes de ventas, etc. en el sitio php utilizando la API de la tienda Magento. Alguien sabe sobre magento Api para obtener información del producto por favor dígame.
Estoy usando este código
<?php
$callbackUrl = "https://air.co.uk/oauth_customer.php";
$temporaryCredentialsRequestUrl = "https://air.co.uk/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = ''https://air.co.uk/oauth/authorize'';
$accessTokenRequestUrl = ''https://air.co.uk/oauth/token'';
$apiUrl = ''https://air.co.uk/api/rest'';
$consumerKey = ''xb4up56a4f95ewl4l5s6xp097wi6g4uwv'';
$consumerSecret = ''ust6oh4t63fw5wcjo8gkqdpgc4tw0iscx'';
session_start();
if (!isset($_GET[''oauth_token'']) && isset($_SESSION[''state'']) && $_SESSION[''state''] == 1) {
$_SESSION[''state''] = 0;
}
try {
$authType = ($_SESSION[''state''] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
if (!isset($_GET[''oauth_token'']) && !$_SESSION[''state'']) {
$requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
$_SESSION[''secret''] = $requestToken[''oauth_token_secret''];
$_SESSION[''state''] = 1;
header(''Location: '' . $adminAuthorizationUrl . ''?oauth_token='' . $requestToken[''oauth_token'']);
exit;
} else if ($_SESSION[''state''] == 1) {
$oauthClient->setToken($_GET[''oauth_token''], $_SESSION[''secret'']);
$accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
$_SESSION[''state''] = 2;
$_SESSION[''token''] = $accessToken[''oauth_token''];
$_SESSION[''secret''] = $accessToken[''oauth_token_secret''];
header(''Location: '' . $callbackUrl);
exit;
} else {
$oauthClient->setToken($_SESSION[''token''], $_SESSION[''secret'']);
$resourceUrl = "$apiUrl/products";
$oauthClient->fetch($resourceUrl);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);
}
} catch (OAuthException $e) {
print_r($e);
}
?>
Pero estoy enfrentando este error
Fatal error: Class ''OAuth'' not found in /home/air/public_html/mapiuse/index.php on line 18
Plese ayuda desde donde agregar la clase OAuth. Y cuál será la mejor solución para conseguir mi trabajo. Gracias
Use Soap Api para mostrar los productos de la tienda de Magento, esto es tan fácil y menos doloroso.
<?php
$mage_url = ''https://domain.com/index.php/api/soap/index/wsdl/1'';
$mage_user = ''Mohammad'';
$mage_api_key = ''XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'';
$soap = new SoapClient( $mage_url );
$session_id = $soap->login( $mage_user, $mage_api_key );
$resources = $soap->resources( $session_id );
// array to store product IDs
$productIDs = array();
$productIndex = array();
// counters
$i = 0;
$s = 0;
// API call to get full product list
$productList = $soap->call($session_id, ''catalog_product.list'');
// Sort through returned array and index what array entry relates to each varient code
if( is_array( $productList ) && !empty( $productList )) {
foreach( $productList as $productListSingle ) {
$sku = $productListSingle[''sku''];
$productIndex[$sku] = $s;
$s++;
}
}
// Sort through the returned product list and populate an array with product IDs
if( is_array( $productList ) && !empty( $productList )) {
foreach( $productList as $productListSingle2 ) {
$productIDs[$i] = $productListSingle2[''product_id''];
$i++;
}
}
// API call for stock levels of product IDs collected above
$productStock = $soap->call($session_id, ''product_stock.list'', array($productIDs));
echo "<table border=/"1/">";
echo "<tr>";
echo "<th width=150>Varient code</th>";
echo "<th width=350>Varient name</th>";
echo "<th width=25>Quantity</th>";
echo "<th width=25>Active</th>";
echo "</tr>";
echo "<tr>";
if( is_array( $productStock ) && !empty( $productStock )) {
foreach( $productStock as $productStockSingle ) {
echo "<tr";
if ($productStockSingle[''qty''] <= 5)
echo " style=/"color:#FF0000;/"";
echo ">";
//Varient code
echo "<td>" . $productStockSingle[''sku''] . "</td>";
//Variables to look up the varient name in the index created above
$skuindex = $productStockSingle[''sku''];
$idindex = $productIndex[$skuindex];
//print varient name using index look up values above
echo "<td>" . $productList[$idindex][''name''] . "</td>";
// varient Quantity in stock
echo "<td>" . $productStockSingle[''qty''] . "</td>";
// Is product marked as in stock (active)?
echo "<td>" . $productStockSingle[''is_in_stock''] . "</td>";
echo "</tr>";
}
}
echo "</tr>";
echo "</table>";
$soap->endSession($session_id);
?>
esto es muy útil