2016-07-28 18 views
1

Ich benutze Magento-1.9-Version und versucht, oauth_token und oauth_token_secret zu generieren.Callback-URL funktioniert nicht in Magento-1.9

Referenz Link: http://devdocs.magento.com/guides/m1x/api/rest/authentication/oauth_authentication.html

Um die oauth_verifier zu bekommen wir müssen die Callback-URL geben. Ich verwende diesen http://localhost/magento/index.php?accepted Link als Rückruf-URL. Aber das funktioniert nicht.

Jeder kann mir helfen, diese URL als Callback-URL zu arbeiten.

Antwort

0
/** 
* Example of retrieving the products list using Admin account via Magento REST API. OAuth authorization is used 
* Preconditions: 
* 1. Install php oauth extension 
* 2. If you were authorized as a Customer before this step, clear browser cookies for 'yourhost' 
* 3. Create at least one product in Magento 
* 4. Configure resource permissions for Admin REST user for retrieving all product data for Admin 
* 5. Create a Consumer 
*/ 
// $callbackUrl is a path to your file with OAuth authentication example for the Admin user 

$baseUrl = 'http://yourhost.abc'; 
$scriptName = $_SERVER['SCRIPT_NAME']; 
$callbackUrl = 'http://scripthost.xyz' . $scriptName; 
$temporaryCredentialsRequestUrl = $baseUrl."/oauth/initiate?oauth_callback=" . urlencode($callbackUrl); 
$adminAuthorizationUrl = $baseUrl.'/admin/oauth_authorize'; 
$customerAuthorizationUrl = $baseUrl.'/oauth/authorize'; 
$accessTokenRequestUrl = $baseUrl.'/oauth/token'; 
$apiUrl = $baseUrl.'/api/rest'; 
$consumerKey = 'Your API consumer key'; 
$consumerSecret = 'Your API consumer key'; 

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: ' . $customerAuthorizationUrl . '?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 { 
     $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']); 
     $resourceUrl = "$apiUrl/products"; 
     $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json')); 
     $productsList = json_decode(json_encode($oauthClient->getLastResponse()), FALSE); 

     echo $productsList; 
    } 
} catch (OAuthException $e) { 
    print_r($e->getMessage()); 
    echo "<br/>"; 
    print_r($e->lastResponse); 
} 

?> 

/** auch Callback-URL ist die gleiche wie die PHP-Skript aufrufen. Mit anderen Worten, Sie müssen zu diesem Skript umleiten. Auch Ihr Callback-Skript und Ihr Server sollten beide auf dem Live-Server oder auf dem lokalen Server sein. */

+0

1- Sie können $ adminAuthorizationUrl für den Zugriff auf Magento Shop-Ressourcen verwenden, indem Sie die Magento 1.x REST API als Admin-Benutzer verwenden. 2- Sie können $ customerAuthorizationUrl verwenden, um mit der Magento 1.x REST API als Kundenbenutzer auf Magento Shop-Ressourcen zuzugreifen. –

+0

Überprüfen Sie die Berechtigungseinstellung in Ihrem Magento Admin-Panel: http://devdocs.magento.com/guides/m1x/api/rest/permission_settings/permission_settings.html –