153 lines
4.4 KiB
Markdown
153 lines
4.4 KiB
Markdown
# 快速开始指南
|
||
|
||
## 5分钟快速上手
|
||
|
||
### 1. 发布小红书图文笔记
|
||
|
||
```python
|
||
import asyncio
|
||
from social_media_auto_publisher import Publisher, ImageNote
|
||
|
||
async def main():
|
||
async with Publisher(headless=False) as publisher:
|
||
# 设置账号(首次需要扫码登录)
|
||
await publisher.setup_platform("xiaohongshu", "your_account")
|
||
|
||
# 创建图文笔记
|
||
note = ImageNote(
|
||
title="我的第一篇笔记",
|
||
description="这是测试内容",
|
||
images=["path/to/image1.jpg", "path/to/image2.jpg"],
|
||
tags=["测试", "分享"]
|
||
)
|
||
|
||
# 发布
|
||
result = await publisher.publish("xiaohongshu", note, "your_account")
|
||
print(f"发布结果: {result.success}")
|
||
|
||
asyncio.run(main())
|
||
```
|
||
|
||
### 2. 发布抖音视频
|
||
|
||
```python
|
||
import asyncio
|
||
from social_media_auto_publisher import Publisher, VideoContent
|
||
|
||
async def main():
|
||
async with Publisher(headless=False) as publisher:
|
||
# 设置账号(首次需要扫码登录)
|
||
await publisher.setup_platform("douyin", "your_account")
|
||
|
||
# 创建视频内容
|
||
video = VideoContent(
|
||
title="我的第一个视频",
|
||
description="这是测试视频描述",
|
||
video_path="path/to/video.mp4",
|
||
tags=["视频", "分享"]
|
||
)
|
||
|
||
# 发布
|
||
result = await publisher.publish("douyin", video, "your_account")
|
||
print(f"发布结果: {result.success}")
|
||
|
||
asyncio.run(main())
|
||
```
|
||
|
||
### 3. 批量发布
|
||
|
||
```python
|
||
import asyncio
|
||
from social_media_auto_publisher import Publisher, ImageNote, PublishTask, PlatformType, AccountInfo
|
||
|
||
async def main():
|
||
async with Publisher(headless=False) as publisher:
|
||
# 创建多个发布任务
|
||
tasks = [
|
||
PublishTask(
|
||
id="task1",
|
||
platform=PlatformType.XIAOHONGSHU,
|
||
account=AccountInfo(PlatformType.XIAOHONGSHU, "user1", "user1.json"),
|
||
content=ImageNote(title="标题1", description="描述1", images=["img1.jpg"])
|
||
),
|
||
PublishTask(
|
||
id="task2",
|
||
platform=PlatformType.DOUYIN,
|
||
account=AccountInfo(PlatformType.DOUYIN, "user1", "user1.json"),
|
||
content=VideoContent(title="标题2", description="描述2", video_path="video1.mp4")
|
||
)
|
||
]
|
||
|
||
# 批量发布
|
||
results = await publisher.batch_publish(tasks)
|
||
for result in results:
|
||
print(f"任务 {result.task_id}: {'成功' if result.success else '失败'}")
|
||
|
||
asyncio.run(main())
|
||
```
|
||
|
||
## 常用功能
|
||
|
||
### 快速发布函数
|
||
|
||
```python
|
||
from social_media_auto_publisher import publish_to_xiaohongshu, publish_to_douyin
|
||
|
||
# 快速发布小红书笔记
|
||
result = await publish_to_xiaohongshu(
|
||
title="标题",
|
||
description="描述",
|
||
images=["img1.jpg"],
|
||
tags=["标签"],
|
||
account_name="your_account"
|
||
)
|
||
|
||
# 快速发布抖音视频
|
||
result = await publish_to_douyin(
|
||
title="标题",
|
||
description="描述",
|
||
video_path="video.mp4",
|
||
tags=["标签"],
|
||
account_name="your_account"
|
||
)
|
||
```
|
||
|
||
### 登录状态检查
|
||
|
||
```python
|
||
async with Publisher() as publisher:
|
||
# 检查登录状态
|
||
is_logged_in = await publisher.test_login("xiaohongshu", "your_account")
|
||
print(f"小红书登录状态: {is_logged_in}")
|
||
```
|
||
|
||
### 内容验证
|
||
|
||
```python
|
||
async with Publisher() as publisher:
|
||
note = ImageNote(title="标题", description="描述", images=["img.jpg"])
|
||
is_valid, error_msg = await publisher.validate_content("xiaohongshu", note)
|
||
print(f"内容验证: {is_valid}, 错误: {error_msg}")
|
||
```
|
||
|
||
## 注意事项
|
||
|
||
1. **首次使用**:需要扫码登录,请确保手机上安装了对应平台的App
|
||
2. **文件路径**:使用绝对路径或确保相对路径正确
|
||
3. **网络环境**:确保网络连接稳定,避免上传中断
|
||
4. **频率控制**:避免过于频繁的发布操作,建议间隔30秒以上
|
||
5. **文件大小**:确保图片和视频文件符合平台要求
|
||
|
||
## 常见问题
|
||
|
||
### Q: 登录时一直等待扫码?
|
||
A: 确保在5分钟内完成扫码,如果超时需要重新开始。
|
||
|
||
### Q: 发布失败提示元素找不到?
|
||
A: 可能是平台页面更新,可以尝试更新到最新版本。
|
||
|
||
### Q: 文件上传失败?
|
||
A: 检查文件格式和大小是否符合平台要求。
|
||
|
||
### Q: 被平台检测为自动化?
|
||
A: 尝试增加操作间隔时间,降低并发数量。 |