Magento休息api电话不能用于我的商店

时间:2014-03-14 07:48:49

标签: php magento rest magento-1.7

我是Magento中REST API的新手。我已经完成了Magento的所有身份验证设置。但请求下面的网址

http://store.mystore.net/api/rest/products

它将响应作为我的商店的网页返回。这一切都与localhost和其他商店一起正常工作。

以下是我的代码:

$storeUrl='http://store.mystore.net';
    $params = array(
        'siteUrl' => $storeUrl,
        'requestTokenUrl' => $storeUrl.'/oauth/initiate',
        'accessTokenUrl' => $storeUrl.'/oauth/token',
        'authorizeUrl' => $storeUrl.'/admin/oauth_authorize',

       'consumerKey' => 'myconsumerkey',
       'consumerSecret' => 'myconsumersecret',
        'callbackUrl' => 'mycallbackurl',//Url of callback action below
    );


    // Initiate oAuth consumer with above parameters
    $consumer = new Zend_Oauth_Consumer($params);
    // Get request token
    $requestToken = $consumer->getRequestToken();

    // Get session
    $_SESSION['requestToken']=serialize($requestToken);
    //$session = Mage::getSingleton('core/session');
    // Save serialized request token object in session for later use
    //$session->setRequestToken(serialize($requestToken));
    // Redirect to authorize URL
    $consumer->redirect();

回调页码

$storeUrl='http://store.mystore.net';
//oAuth parameters
$params = array(
    'siteUrl' => $storeUrl.'/oauth',
    'requestTokenUrl' => $storeUrl.'/oauth/initiate',
    'accessTokenUrl' => $storeUrl.'/oauth/token',

    'consumerKey' => 'myconsumerkey',
    'consumerSecret' => 'mysecretkey'
);


$requestToken = unserialize($_SESSION['requestToken']);
// Initiate oAuth consumer
$consumer = new Zend_Oauth_Consumer($params);
// Using oAuth parameters and request Token we got, get access token
$acessToken = $consumer->getAccessToken($_GET, $requestToken);
 echo $acessToken;
// Get HTTP client from access token object
$restClient = $acessToken->getHttpClient($params);
// Set REST resource URL?
$restClient->setUri('http://store.mystore.net/api/rest/products');

// configure for request time out
  $restClient->setConfig(array(
//'maxredirects' => 0,
'timeout'      => 3000));
// In Magento it is neccesary to set json or xml headers in order to work
$restClient->setHeaders('Accept', 'application/json');
// Get method
$restClient->setMethod(Zend_Http_Client::GET);

//Make REST request
$response = $restClient->request();

// Here we can see that response body contains json list of products

Zend_Debug::dump($response);

我已在管理员面板中设置了用户角色和属性。帮助我解决这个问题。

由于

1 个答案:

答案 0 :(得分:0)

由于您的令牌被拒绝,请正确检查身份验证。

您可以在Mozila Rest Client中进行测试。