"http: // {root_dir} / oauth / token" File not found in Magento to register REST API application

I have a written code in ZEND for accessing the Magento REST API for accessing data.

<?php require_once 'Zend/Oauth/Consumer.php'; class AuthController extends Zend_Controller_Action { public function init() { $this->hostname = 'http://localhost/magento'; $consumerKey = 'mkkzxuu1bkveejyzjam5hl2pzaxxepwv'; $consumerSecret = 'bcmczrp3ofn9vmviqu3j8o1ioa7fisl6'; $callbackUrl = 'http://localhost/magento/oauth/token'; $this->config = array( 'callbackUrl' => $callbackUrl, 'requestTokenUrl' => $this->hostname . '/oauth/initiate', 'siteUrl' => $this->hostname . '/oauth', 'consumerKey' => $consumerKey, 'consumerSecret' => $consumerSecret, 'authorizeUrl' => $this->hostname . '/admin/oauth_authorize', // 'authorizeUrl' => $this->hostname . '/oauth/authorize', 'accessTokenUrl' => $this->hostname . '/oauth/token' ); } public function indexAction() { $accesssession = new Zend_Session_Namespace('AccessToken'); if (isset($accesssession->accessToken)) { $token = unserialize($accesssession->accessToken); // $client = $token->getHttpClient($this->config); $client = new Zend_Http_Client(); $adapter = new Zend_Http_Client_Adapter_Curl(); $client->setAdapter($adapter); $adapter->setConfig(array( 'adapter' => 'Zend_Http_Client_Adapter_Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true), )); $client->setUri($this->hostname . '/api/rest/products'); $client->setParameterGet('oauth_token', $token->getToken()); echo $token->getToken(); echo $token->getTokenSecret(); $client->setParameterGet('oauth_token_secret', $token->getTokenSecret()); $response = $client->request('GET'); $products = Zend_Json::decode($response->getBody()); } else { $consumer = new Zend_Oauth_Consumer($this->config); $token = $consumer->getRequestToken(); $requestsession = new Zend_Session_Namespace('RequestToken'); $requestsession->requestToken = serialize($token); $consumer->redirect(); } $this->view->products = $products; } public function callbackAction() { $requestsession = new Zend_Session_Namespace('RequestToken'); if (!empty($_GET) && isset($requestsession->requestToken)) { $accesssession = new Zend_Session_Namespace('AccessToken'); $consumer = new Zend_Oauth_Consumer($this->config); $token = $consumer->getAccessToken( $_GET, unserialize($requestsession->requestToken) ); $accesssession->accessToken = serialize($token); // Now that we have an Access Token, we can discard the Request Token // unset($requestsession->requestToken); // $this->_redirect(); $this->_forward('index', 'index', 'default'); } else { // Mistaken request? Some malfeasant trying something? // throw new Exception('Invalid callback request. Oops. Sorry.'); } } public function callbackrejectedAction() { // rejected } } 

I tried this URL many times

 http://localhost/magento/oauth/token?oauth_token=medensg02pvrd1rdfjcay4bwkr76whkk&oauth_verifier=qxvbth1rfe4vv78n7r6mprtxvuq2yqhb 

but gets nothing but a file not found.

You can see that this url exists on the official magento resource. http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html

After Calling this controller belows request generate for authorize after accepting this.

Throws belows error file not founds.

+6
source share
1 answer

First of all, you need to install the oauth extension for php, if it is already installed, than check your phpinfo that it is enabled. Then go to admin section and make the following changes to check rest api answer.

admin->system->Webservice->rest attribute->guest->resources access and set ALL

 admin->system->webservice->rest roles->guest->resources access and set ALL 

save settings and click on your URL

 http://hostname/magento/api/rest/products/ 

it will show you the answer in xml format.later to change access to the resource according to your requirement.

after you make sure magento is responding to the reset api, than your code is running, and I feel that it will work.

+2
source

Source: https://habr.com/ru/post/949741/


All Articles