0

I am using Magento 1.9, REST API getting problem when trying to get data using API. Here is the screenshot . If any one here to help. it's ok on guest user and customer user but problem on admin .

enter image description here

0

Create rest.php file in you root folder

<?php

$magentoUrl = "http://yoursite.com/subfolder/";
$consumerKey = 'consumer Key';
$consumerSecret = 'consumer Secret';



$callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}/{$_SERVER['REQUEST_URI']}";
$temporaryCredentialsRequestUrl = "{$magentoUrl}/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = "{$magentoUrl}/admin/oauth_authorize";
$accessTokenRequestUrl = "{$magentoUrl}/oauth/token";
$apiUrl = '{$magentoUrl}/api/rest';


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 {
        echo "<pre>";
        echo "Consumer Key: " . print_r($consumerKey, true). "\n";
        echo "Consumer Secret: " . print_r($consumerSecret, true). "\n";
        echo "\n\n";
        echo "Token Key: " . print_r($_SESSION['token'], true). "\n";
        echo "Token Secret: " . print_r($_SESSION['secret'], true). "\n\n";
        unset($_SESSION['state']);
        unset($_SESSION['secret']);
    }
} catch (OAuthException $e) {
    print_r($e);
}

Use this code and yoursite.com/rest.php

Done and get Authorize your app . Now you can see your Token Key and Token Secret . use it any where ...

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.