I have created a shopping site in magento now I would like to set up its mobile app using REST API. To set up, In the backend, I created an admin REST Role named “programmer” with all api resource access. Next, I set my REST Attributes for admin to give it all resource access. Finally I created a REST Consumer named “programmer”.
I am using the code from the net
$callbackUrl = "http://localhost/magento/oauth_customer.php";
$temporaryCredentialsRequestUrl = "http://localhost/magento/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://localhost/magento/oauth/authorize';
$accessTokenRequestUrl = "http://localhost/magento/oauth/token";
$apiUrl = "http://localhost/magento/api/rest";
$consumerKey = '5cba48f94ed1037c815c24d10659bab6';
$consumerSecret = '1f27ba3a51f9779e5ed0d366c4d7dfff';
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);
}
he code returns following errors:
Notice: Undefined index: state in /Applications/XAMPP/xamppfiles/htdocs/magento/oauth_customer.php on line 16
Notice: Use of undefined constant OAUTH_AUTH_TYPE_URI - assumed 'OAUTH_AUTH_TYPE_URI' in /Applications/XAMPP/xamppfiles/htdocs/magento/oauth_customer.php on line 16
Fatal error: Uncaught Error: Class 'OAuth' not found in /Applications/XAMPP/xamppfiles/htdocs/magento/oauth_customer.php:17 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/magento/oauth_customer.php on line 17