1、打開賣家的后臺,打開設置
2、將頁面翻到最底部,然后打開api密鑰管理
3、賬號分兩個,一個是生產環境,一個是沙盒環境(測試環境),切記,無論什么環境,都有調用的次數限制(有些接口沒有限制,比如獲取授權token),具體是多少我也不清楚,每一個店鋪賬號都不一樣,需要問客服
4、然后我們要復制一下【ClientID】和【ClientSecret】,【ClientSecret】需要打開控制臺進行復制,打開控制臺后定位到【ClientSecret】位置,在html代碼里復制,如果還不會操作,評論里問一下。
5、python代碼直接演示,把剛剛復制的內容粘貼進去即可請求
【附上代碼】
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 經過base64加密,獲取Basic Authorization 頭部授權信息
'''
credentials = f"{client_id}:{client_secret}"
encoded_credentials = base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
return f"Basic {encoded_credentials}"
# 獲取生產環境Token
def get_production_access_token(authorization, shop_settings):
'''
:param authorization: Basic Authorization 頭部授權信息
:param shop_settings: 字典格式 {'account_name': 'xiaoming'} account_name 指向用你的沃爾瑪賬號名稱
:return: {"access_token":"eyJraWQiOiIyZTBh......“,"token_type":"Bearer","expires_in":900}
'''
# 設置請求頭
"Authorization": authorization,
"WM_SVC.NAME": shop_settings['account_name'],
"WM_QOS.CORRELATION_ID": str(uuid.uuid4()), # UUID要隨機
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"
}
try:
# https://marketplace.walmartapis.com/v3/token 生產環境
# https://sandbox.walmartapis.com/v3/token # 測試環境
# 發起 POST 請求
response = requests.post(
url="https://marketplace.walmartapis.com/v3/token",
headers=headers,
data="grant_type=client_credentials"
)
# 打印響應信息(調試用)
print("響應狀態碼:", response.status_code)
print("響應文本:", response.text)
if response.status_code != 200:
raise Exception(f"請求失敗,狀態碼: {response.status_code}")
# 解析返回的 JSON 數據
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"獲取生產環境 Token 異常: {str(e)}")
return None
# 示例調用
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"生產環境的 Access Token: {token}")
審核編輯 黃宇
-
接口
+關注
關注
33文章
9454瀏覽量
156324 -
API
+關注
關注
2文章
2198瀏覽量
66345 -
沃爾瑪
+關注
關注
0文章
134瀏覽量
14151 -
python
+關注
關注
57文章
4861瀏覽量
89671
發布評論請先 登錄
Rakuten API 接口調用:從準備到落地的實操指南
小紅書獲取筆記正文和點贊數的API接口
淘寶平臺獲取商品視頻 API 接口技術指南
淘寶商品詳情API接口技術解析與實戰應用
深入了解系統調用API:探索操作系統底層的關鍵接口
Python調用API教程
如何通過API獲取拼多多商品詳情數據?

【Python 沃爾瑪接口調用】調用沃爾瑪官方接口獲取授權access_token
評論