2

I am getting issue while creating Magento Rest Api for Mobile Application. I have a php file containing logic to access Magento Rest Api. Whenever I am hitting the file it is redirecting to me customer authorization login form after entering the details it sending to customer dashboard but i want it to redirect to my php file with json response. My php file Code is :

$callbackUrl = "host/Makery/prashant.php";

$temporaryCredentialsRequestUrl = "host/Makery/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);`

$adminAuthorizationUrl = 'host/Makery/oauth/authorize';`

$accessTokenRequestUrl = 'host/Makery/oauth/token';`

$apiUrl = 'http://127.0.0.1/Makery/api/rest';`

$consumerKey = 'ed28ffc6263b00337cb9de3eaae17b1d';`

$consumerSecret = '045422b7d1cb5c5bfb025c4411a18162';`



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, array(), 'GET', array('Content-Type' => 'application/json'));
        //$productsList = json_decode($oauthClient->getLastResponse());
        //var_dump($productsList);
        echo $oauthClient->getLastResponse();
    }
} catch (OAuthException $e) {
    print_r($e->getMessage());
    echo "<br/>";
    print_r($e->lastResponse);
}

Your Answer

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

Browse other questions tagged or ask your own question.