Walmart Seller API POST无法正常工作,仅在PHP中提供未经授权的401 [英] Walmart Seller API POST not working, Gives 401 unauthorized in PHP only
问题描述
我正在尝试使用CURL PHP确认GET Walmart Seller API. 谁能建议我需要使用哪个RSA PHP库?这样,在调用walmart时就可以验证身份验证签名.
I am trying to GET Walmart Seller API using CURL PHP to acknowledge. Can any one suggest which RSA PHP library i need to use ? So that Authentication Signature is verify while making calls to walmart.
任何人有这种经历吗?
$headers = array(
'WM_SVC.NAME: Walmart Marketplace',
'WM_QOS.CORRELATION_ID: 14730688612',
'WM_SEC.TIMESTAMP:14730688612',
'WM_SEC.AUTH_SIGNATURE: XXXXXXXXXXX'
'WM_CONSUMER.ID: XXXXXXXXXXX',
'Content-Type: application/xml',
'Accept: application/xml',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL,$requestUrl);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec( $ch );
if(curl_errno($ch)):
echo 'Curl error: '.curl_error($ch);
endif;
我使用了谷歌搜索时找到的参考.
I have used reference that found while googling.
- https://github.com/fillup/walmart-auth-signature-php
推荐答案
在2018年8月之后的新API中,您必须生成访问令牌,然后使用完全独立的身份验证标头从其API中提取任何内容.花了几个小时才弄清楚这一点,所以我希望这对以后的人有所帮助.
In the new API after August of 2018, you have to generate an access token AND then use a completely separate authentication header to pull anything from their API. It took a couple of hours just to figure this out, so I hope this helps someone in the future.
(这适用于Marketplace API,但适用于任何Walmart API)
要生成访问令牌,您必须传递以下标头:
To generate the access token, you have to pass these headers:
Array(
[0] => Authorization: Basic BASE64_ENCODED_VARIABLE (see below)
[1] => Content-Type: application/x-www-form-urlencoded
[2] => Accept: application/json
[3] => WM_SVC.NAME: Walmart Marketplace
[4] => WM_QOS.CORRELATION_ID: 10_DIGIT_RANDOM_GENERATED_ALPHANUMERIC_ID
[5] => WM_SVC.VERSION: 1.0.0
[6] => WM_CONSUMER.CHANNEL.TYPE: PROVIDED_WHEN_GENERATING_CLIENT_ID_AND_SECRET
)
要生成BASE64_ENCODED_VARIABLE,请使用base64_encode创建一个变量,如下所示:
To generate BASE64_ENCODED_VARIABLE, create a variable using base64_encode as such:
$auth = base64_encode($clientId . ":" . $clientSecret);
...其中,客户端ID和客户端机密是从沃尔玛的开发人员门户API区域生成的.
...where Client ID and Client Secret are generated from Wal-Mart's Developer Portal API area.
=========================================
===========================================
在将数据成功发布到沃尔玛并收到访问令牌作为回报之后,您想在您使用沃尔玛进行的任何API调用中传递以下标头:
After you successfully POST that data to Walmart and receive an Access Token in return, you want to pass the following headers in ANY API CALL you make with Wal-Mart:
Array(
[0] => Authorization: Basic BASE64_ENCODED_VARIABLE (as described above)
[1] => WM_SVC.NAME: Walmart Marketplace
[2] => WM_QOS.CORRELATION_ID: 10_DIGIT_RANDOM_GENERATED_ALPHANUMERIC_ID
[3] => WM_CONSUMER.CHANNEL.TYPE: PROVIDED_WHEN_GENERATING_CLIENT_ID_AND_SECRET
[4] => WM_SEC.ACCESS_TOKEN: GENERATED_FROM_PREVIOUS_STEP (returned as [access_token])
[5] => Content-Type: application/json
[6] => Accept: application/json
)
...然后拨打电话.
...then make your calls.
这是在连续不断收到UNAUTHORIZED.GMP_GATEWAY_API错误之后,终于为我工作的原因.
This is what FINALLY worked for me after continuously receiving UNAUTHORIZED.GMP_GATEWAY_API errors across the board.
传递授权:承载令牌令牌",而不是我上面 将不起作用 列出的方式作为身份验证标头.相信我:-)
Passing "Authorization: Bearer TOKENTOKENTOKEN" instead of the way I've listed above WILL NOT WORK as the authentication header. Trust me :-)
这篇关于Walmart Seller API POST无法正常工作,仅在PHP中提供未经授权的401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!