php - "http://{root_dir}/oauth/token" File Not Found in Magento to register REST API application -
i have written code in zend accessing magento rest api 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); // have access token, can discard request token // unset($requestsession->requesttoken); // $this->_redirect(); $this->_forward('index', 'index', 'default'); } else { // mistaken request? malfeasant trying something? // throw new exception('invalid callback request. oops. sorry.'); } } public function callbackrejectedaction() { // rejected } } i have try url many time
http://localhost/magento/oauth/token?oauth_token=medensg02pvrd1rdfjcay4bwkr76whkk&oauth_verifier=qxvbth1rfe4vv78n7r6mprtxvuq2yqhb but not getting rather file not found error.
you can see url exist @ magento official resource. http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html


first of need install oauth extension php, if it's install check phpinfo it's enabled. go admin section , make following changes check response of rest api.
admin->system->webservice->rest attribute->guest->resources access , set all
admin->system->webservice->rest roles->guest->resources access , set save settings , hit url
http://hostname/magento/api/rest/products/ it show response in xml format.later on modify resource access per requirement.
once make sure magento responding reset api run code , feel work.
Comments
Post a Comment