ReaJason / xhs

基于小红书 Web 端进行的请求封装。https://reajason.github.io/xhs/
MIT License
1.03k stars 295 forks source link

发布笔记接口,topics好像无效 #68

Closed zhouyangit closed 10 months ago

zhouyangit commented 10 months ago

大佬你好,我使用 test_create_note_with_ats_topics() 这个接口

topics 按照规定的格式传入,成功发布后,文中的标签还是文本,不能直接点击,请问还是需要设置什么吗?

topics = [ { "id": "5d35dd9b000000000e0088dc", "name": "Python", "type": "topic", "link": "https://www.xiaohongshu.com/page/topics/5d35dd9ba059940001703e38?naviHidden=yes" }, { "id": "5d35dd9b000000000e0088dc", "name": "Python", "type": "topic", "link": "https://www.xiaohongshu.com/page/topics/5d35dd9ba059940001703e38?naviHidden=yes" } ]

ReaJason commented 10 months ago

请发送完成的脚本代码

zhouyangit commented 10 months ago

def test_create_note_with_ats_topics(xhs_client: XhsClient):
    title = "我是通过自动发布脚本发送的笔记"
    desc = "deployed by GitHub xhs, #Python[话题]# @ReaJason"
    # files = [
    #     "/Users/reajason/Downloads/221686462282_.pic.png",
    # ]

    files = get_image_paths()

    # 可以通过 xhs_client.get_suggest_ats(ats_keyword) 接口获取用户数据
    ats = [
        {"nickname": "ReaJason", "user_id": "63273a77000000002303cc9b", "name": "ReaJason"}
    ]

    # 可以通过 xhs_client.get_suggest_topic(topic_keyword) 接口获取标签数据
    topics = [
        {
            "id": "5d35dd9b000000000e0088dc", "name": "Python", "type": "topic",
            "link": "https://www.xiaohongshu.com/page/topics/5d35dd9ba059940001703e38?naviHidden=yes"
        },
        {
            "id": "5d35dd9b000000000e0088dc", "name": "Python", "type": "topic",
            "link": "https://www.xiaohongshu.com/page/topics/5d35dd9ba059940001703e38?naviHidden=yes"
        }
    ]
    note = xhs_client.create_image_note(title, desc, files, topics=topics, is_private=True,
                                        post_time="2023-07-25 23:59:59")
    beauty_print(note)```

发布成功了,但是查看发布的笔记,topics设置的 Python 还是纯文本,不是标签
ReaJason commented 10 months ago

麻烦根据用例来,用例是可以的,maybe 是因为你 topics 里面传了重复的?

IMG_1202

zhouyangit commented 10 months ago

解决了 :)

 ...
 desc = "deployed by GitHub xhs, #Python[话题]#"
...

话题格式需要按照 #话题[话题]# 格式来