0

I am using Magento 1.9, REST API getting problem when trying to get data using API. Here is the screenshot . If any one here to help. it's ok on guest user and customer user but problem on admin .

enter image description here

asked Apr 22, 2018 at 5:46

1 Answer 1

0

Create rest.php file in you root folder

<?php
$magentoUrl = "http://yoursite.com/subfolder/";
$consumerKey = 'consumer Key';
$consumerSecret = 'consumer Secret';
$callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}/{$_SERVER['REQUEST_URI']}";
$temporaryCredentialsRequestUrl = "{$magentoUrl}/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = "{$magentoUrl}/admin/oauth_authorize";
$accessTokenRequestUrl = "{$magentoUrl}/oauth/token";
$apiUrl = '{$magentoUrl}/api/rest';
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 {
 echo "<pre>";
 echo "Consumer Key: " . print_r($consumerKey, true). "\n";
 echo "Consumer Secret: " . print_r($consumerSecret, true). "\n";
 echo "\n\n";
 echo "Token Key: " . print_r($_SESSION['token'], true). "\n";
 echo "Token Secret: " . print_r($_SESSION['secret'], true). "\n\n";
 unset($_SESSION['state']);
 unset($_SESSION['secret']);
 }
} catch (OAuthException $e) {
 print_r($e);
}

Use this code and yoursite.com/rest.php

Done and get Authorize your app . Now you can see your Token Key and Token Secret . use it any where ...

answered Apr 23, 2018 at 6:58
1
  • It is not working for me...! same as above mention please give me other solutions Commented Sep 24, 2020 at 12:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.