在Magento中如何获得AccessToken和Access Secret Token

时间:2013-01-04 07:47:13

标签: magento magento-1.7 magento-1.4

我已将Advanced Rest Client安装到我的chrome中。从我的magento我可以从管理面板获取消费者密钥和密钥。我试图从链接http://term.ie/oauth/example/client.php获取令牌,但它以下列方式返回..这里没有令牌密钥..

request url: ://192.168.1.101:8000/magento/admin/oauth/token ?oauth_version=1.0&oauth_nonce=XXXXXXXXX&oauth_timestamp=XXXXXXX&oauth_consumer_key=xxxxxxxxx&oauth_signature_method=HMAC-SHA1&oauth_signature=xxxxxxxxx%3D
OAuthRequest Object
(
    [parameters:OAuthRequest:private] => Array
        (
            [oauth_version] => 1.0
            [oauth_nonce] => XXXXXXXXXX
            [oauth_timestamp] => XXXXXXX
            [oauth_consumer_key] => XXXXXXXXXXXXXXXXXXXXXXXXXXX
            [oauth_signature_method] => HMAC-SHA1
            [oauth_signature] => XXXXXXXXXXXXXXXXXXXX=
        )

    [http_method:OAuthRequest:private] => GET
    [http_url:OAuthRequest:private] => 192.168.1.101:8010/magento/admin/oauth/token 
    [base_string] => GET&%3A%2F%2F192.168.1.101%2Fmagento%2Fadmin%2Foauth%2Ftoken%20&oauth_consumer_key%XXXXXXXXXXXXXXXXXXXXXXX%26oauth_nonce%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX%26oauth_signature_method%XXXXXXXXXX%26oauth_timestamp%XXXXXXXXX%26oauth_version%3D1.0
)

所以建议我如何获得访问令牌和访问秘密令牌....

1 个答案:

答案 0 :(得分:2)

据我所知,您已经为REST创建了管理员角色& OAUTH消费者所以我正在抓它。

在root下面创建test.php文件。用您的值替换CONSUMERKEY和CONSUMERSECRET。

<?php
/**

* Example of update product record via Magento REST API. OAuth authorization is used

*/

$callbackUrl = "http://yourhost/test.php";
$temporaryCredentialsRequestUrl = "http://yourhost/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://yourhost/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://yourhost/oauth/token';
$apiUrl = 'http://yourhost/api/rest';
$consumerKey = '[your consumer key here]';
$consumerSecret = '[your consumer Secret here]';



echo "<pre/>";

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();

$oauthClient->disableSSLChecks();



if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {

$requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
echo "<pre>";print_r($requestToken);die();
$_SESSION['secret'] = $requestToken['oauth_token_secret'];

$_SESSION['state'] = 1;

header("Location: " . $adminAuthorizationUrl . "?oauth_token=" . $requestToken['oauth_token']);

exit;

} 

&GT;

并且上面的输出应该是数组

Array
(
    [oauth_token] => "tokenkey"
    [oauth_token_secret] => "token secret"
    [oauth_callback_confirmed] => true
)

希望这对你有所帮助。