简体   繁体   English

在Magento中找不到“ http:// {root_dir} / oauth / token”文件来注册REST API应用程序

[英]“http://{root_dir}/oauth/token” File Not Found in Magento to register REST API application

I have Written code in ZEND For Accessing Magento REST API for accessing data. 我在ZEND中编写了用于访问Magento REST API的代码以访问数据。

<?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 have try this url many time 我已经尝试了很多次

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

but not getting anything rather than File not found error. 但没有得到任何东西,而不是没有找到文件错误。

You can see this url exist at magento official resource. 您可以在magento官方资源中看到此url。 http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html

调用此控制器后,接受此请求后将生成授权请求。

找不到以下错误文件。

First of all you need to install oauth extension for php, if it's already install than check your phpinfo that it's enabled. 首先,您需要为php安装oauth扩展(如果已安装),然后检查phpinfo是否已启用。 Than go to admin section and make the following changes to check the response of rest api. 比转到管理部分,进行以下更改以检查rest api的响应。

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

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

save the settings and hit your url 保存设置并点击您的网址

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

it will show you the response in xml format.later on modify the resource access as per your requirement. 它将以xml格式显示响应。稍后根据您的要求修改资源访问权限。

once you make sure that magento is responding to the reset api than run your code and I feel it will work. 一旦您确定magento响应了重置api而不是运行您的代码,我就认为它会工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM