1、打開賣家的后臺,打開設(shè)置
2、將頁面翻到最底部,然后打開api密鑰管理
3、賬號分兩個,一個是生產(chǎn)環(huán)境,一個是沙盒環(huán)境(測試環(huán)境),切記,無論什么環(huán)境,都有調(diào)用的次數(shù)限制(有些接口沒有限制,比如獲取授權(quán)token),具體是多少我也不清楚,每一個店鋪賬號都不一樣,需要問客服
4、然后我們要復(fù)制一下【ClientID】和【ClientSecret】,【ClientSecret】需要打開控制臺進(jìn)行復(fù)制,打開控制臺后定位到【ClientSecret】位置,在html代碼里復(fù)制,如果還不會操作,評論里問一下。
5、python代碼直接演示,把剛剛復(fù)制的內(nèi)容粘貼進(jìn)去即可請求
【附上代碼】
import base64
import requests
import uuid
import json
# 獲取 Basic Authorization
def get_authorization(client_secret, client_id):
'''
:param client_secret: Client Secret
:param client_id: Client ID
:return: 將 Client ID 和 Client Secret 經(jīng)過base64加密,獲取Basic Authorization 頭部授權(quán)信息
'''
credentials = f"{client_id}:{client_secret}"
encoded_credentials = base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
return f"Basic {encoded_credentials}"
# 獲取生產(chǎn)環(huán)境Token
def get_production_access_token(authorization, shop_settings):
'''
:param authorization: Basic Authorization 頭部授權(quán)信息
:param shop_settings: 字典格式 {'account_name': 'xiaoming'} account_name 指向用你的沃爾瑪賬號名稱
:return: {"access_token":"eyJraWQiOiIyZTBh......“,"token_type":"Bearer","expires_in":900}
'''
# 設(shè)置請求頭
"Authorization": authorization,
"WM_SVC.NAME": shop_settings['account_name'],
"WM_QOS.CORRELATION_ID": str(uuid.uuid4()), # UUID要隨機(jī)
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"
}
try:
# https://marketplace.walmartapis.com/v3/token 生產(chǎn)環(huán)境
# https://sandbox.walmartapis.com/v3/token # 測試環(huán)境
# 發(fā)起 POST 請求
response = requests.post(
url="https://marketplace.walmartapis.com/v3/token",
headers=headers,
data="grant_type=client_credentials"
)
# 打印響應(yīng)信息(調(diào)試用)
print("響應(yīng)狀態(tài)碼:", response.status_code)
print("響應(yīng)文本:", response.text)
if response.status_code != 200:
raise Exception(f"請求失敗,狀態(tài)碼: {response.status_code}")
# 解析返回的 JSON 數(shù)據(jù)
response_data = json.loads(response.text)
access_token = response_data.get("access_token")
if not access_token:
raise Exception("獲取 Token 失敗")
print(f"生成的 Token: {access_token}")
return access_token
except Exception as e:
print(f"獲取生產(chǎn)環(huán)境 Token 異常: {str(e)}")
return None
# 示例調(diào)用
shop_settings = {
'account_name': 'xxxxxxx' # 你的沃爾瑪賬號名稱 或者自定義 比如:zhangfei
}
# 替換為你的 Client ID 和 Client Secret
ClientID = "xxxxx-xxx-xxx-8e31-xxxxxxxx"
ClientSecret = "UxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxWWg"
authorization = get_authorization(ClientSecret, ClientID)
token = get_production_access_token(authorization, shop_settings)
# 輸出 token
print(f"生產(chǎn)環(huán)境的 Access Token: {token}")
審核編輯 黃宇
-
接口
+關(guān)注
關(guān)注
33文章
9439瀏覽量
156071 -
API
+關(guān)注
關(guān)注
2文章
2131瀏覽量
66174 -
沃爾瑪
+關(guān)注
關(guān)注
0文章
134瀏覽量
14138 -
python
+關(guān)注
關(guān)注
57文章
4856瀏覽量
89523
發(fā)布評論請先 登錄
Rakuten API 接口調(diào)用:從準(zhǔn)備到落地的實(shí)操指南
小紅書獲取筆記正文和點(diǎn)贊數(shù)的API接口
快手平臺獲取視頻評論API接口技術(shù)指南
通過接口獲取攜程酒店詳情數(shù)據(jù)的技術(shù)實(shí)現(xiàn)
1688平臺關(guān)鍵字搜索商品API接口技術(shù)實(shí)踐指南
調(diào)用拼多多開放平臺 API 獲取店鋪列表
淘寶平臺獲取商品視頻 API 接口技術(shù)指南
淘寶商品詳情API接口技術(shù)解析與實(shí)戰(zhàn)應(yīng)用
深入了解系統(tǒng)調(diào)用API:探索操作系統(tǒng)底層的關(guān)鍵接口
Python調(diào)用API教程
如何通過API獲取拼多多商品詳情數(shù)據(jù)?

【Python 沃爾瑪接口調(diào)用】調(diào)用沃爾瑪官方接口獲取授權(quán)access_token
評論