100 lines
3.3 KiB
Python
100 lines
3.3 KiB
Python
"""
|
||
测试新接口(达人列表)是否只需Cookie就能访问
|
||
"""
|
||
import sys
|
||
from core.api_client import ByteDanceAPIClient
|
||
from utils.logger import logger
|
||
|
||
|
||
def test_daren_list_api():
|
||
"""测试达人列表接口"""
|
||
print("\n" + "="*60)
|
||
print("🧪 测试达人列表接口")
|
||
print("="*60)
|
||
|
||
# 创建API客户端
|
||
client = ByteDanceAPIClient()
|
||
|
||
# 检查Cookie是否存在
|
||
if not client.cookie_manager.is_cookie_exists():
|
||
print("\n❌ Cookie不存在,请先登录:")
|
||
print(" python main.py login")
|
||
return False
|
||
|
||
print("\n✅ Cookie已存在")
|
||
print(f"📁 Cookie文件: {client.cookie_manager.cookie_file}")
|
||
|
||
# 测试接口
|
||
print("\n📡 正在请求接口...")
|
||
print("接口: /ecom/mcn/bind/daren/account")
|
||
print("参数: page=1, pageSize=20, status=1")
|
||
|
||
try:
|
||
data = client.get_daren_list(page=1, page_size=20, status=1)
|
||
|
||
if data is None:
|
||
print("\n❌ 请求失败,返回None")
|
||
print("\n💡 可能的原因:")
|
||
print(" 1. Cookie已失效,请重新登录:python main.py login")
|
||
print(" 2. 接口需要验签参数(a_bogus、msToken等)")
|
||
print(" 3. 网络问题")
|
||
return False
|
||
|
||
# 检查响应状态
|
||
st = data.get('st', -1)
|
||
code = data.get('code', -1)
|
||
msg = data.get('msg', '')
|
||
|
||
if st != 0 or code != 0:
|
||
print(f"\n⚠️ 接口返回错误:")
|
||
print(f" st: {st}")
|
||
print(f" code: {code}")
|
||
print(f" msg: {msg}")
|
||
|
||
if code == 401 or code == 403:
|
||
print("\n💡 认证失败,可能需要:")
|
||
print(" 1. 重新登录:python main.py login")
|
||
print(" 2. 添加验签参数")
|
||
return False
|
||
|
||
return False
|
||
|
||
# 成功获取数据
|
||
print("\n✅ 请求成功!")
|
||
print("\n📊 响应数据:")
|
||
print(f" 状态码: st={st}, code={code}")
|
||
|
||
# 解析数据
|
||
if 'data' in data:
|
||
data_obj = data['data']
|
||
total = data_obj.get('total', 0)
|
||
daren_list = data_obj.get('daren_list', [])
|
||
|
||
print(f" 总数: {total}")
|
||
print(f" 当前页: {len(daren_list)} 条数据")
|
||
|
||
if daren_list:
|
||
print("\n📝 前3条数据示例:")
|
||
for i, daren in enumerate(daren_list[:3], 1):
|
||
print(f"\n {i}. {daren.get('user_name', 'Unknown')}")
|
||
print(f" 粉丝数: {daren.get('fans_count', 0):,}")
|
||
print(f" User ID: {daren.get('user_id', '')}")
|
||
print(f" 本月直播: {daren.get('month_live_count', 0)} 场")
|
||
print(f" 本月视频: {daren.get('month_video_count', 0)} 个")
|
||
|
||
print("\n" + "="*60)
|
||
print("🎉 结论:接口只需Cookie即可访问,无需验签!")
|
||
print("="*60)
|
||
return True
|
||
|
||
except Exception as e:
|
||
print(f"\n❌ 测试过程发生异常: {e}")
|
||
logger.error(f"测试异常: {e}", exc_info=True)
|
||
return False
|
||
|
||
|
||
if __name__ == "__main__":
|
||
success = test_daren_list_api()
|
||
sys.exit(0 if success else 1)
|
||
|