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';
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
    $_SESSION['state'] = 0;
try {
    $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);

    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']);
    } 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);
    } else {
        $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
        $resourceUrl = "$apiUrl/products";
        $productsList = json_decode($oauthClient->getLastResponse());
} catch (OAuthException $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

1 Answer 1


It seems that php extension OAUTH is not installed. Firstly you need to download related php version oauth dll file for your php. Then you will need to add it in file strucutre and adding entry in php.ini. Once its done you can restart your wamp and along with all other extension ouath will be shown at php extensions.

you may refer link @ https://stackoverflow.com/questions/9819107/how-to-install-the-oauth-in-php

  • I am using latest version of XAMPP server on osx
    – user
    Aug 11, 2016 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.