Magentoで新しい顧客を作成しようとしています。これが私がそのために書いたPHPスクリプトです
<?php
$callbackUrl = "http://localhost/magento/webservices/NewCustomer1.php";
$temporaryCredentialsRequestUrl = "http://localhost/magento/oauth/initiate?oauth_callback=". urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://localhost/magento/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://localhost/magento/oauth/token';
$apiUrl = 'http://localhost/magento/api/rest';
$consumerKey = 's3xt7w8lwhfrrfzrfvwm3lrilkf66d5n';
$consumerSecret = 'vr3eq1x899pz1cf4zzxjzx3q03t66r3n';
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 {
$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
$resourceUrl = "$apiUrl/customers/create";
$customerData = json_encode(array(
'firstname' => 'demofirstname',
'lastname' => 'demolastname',
'email_address' => 'demo@gmail.com',
'password' => 'demo1234',
'confirmation' => 'demo1234',
));
$headers = array('Content-Type' => 'application/json');
$oauthClient->fetch($resourceUrl, $customerData, OAUTH_HTTP_METHOD_POST, $headers);
print_r($oauthClient->getLastResponseInfo());
}
} catch (OAuthException $e) {
print_r($e);
}
?>
このエラーが発生します
OAuthException:47行目のC:\ wamp \ www \ magento \ WebServices \ newcustomer1.phpの無効な認証/不正なリクエスト(405、予想されるHTTP / 1.1 20Xまたはリダイレクト)コールスタック#TimeMemoryFunctionLocation 10.0010386016 {main}()。 。\newcustomer1.php:0 20.0017391216OAuth-> fetch().. \ newcustomer1.php:47)
私はOauthとPHPを初めて使用します。誰かが助けてくれたら嬉しいです。