Actions¶
This section lists APIs that performs actions with POST, PUT or DELETE. Actions are done with the current account. Assuming you have created an instance:
from zhihuAPI.account import ZhihuAccount
machine = ZhihuAccount('path/to/cookie.json')
Account¶
Send Message (发送私信)¶
You need to pass additional information as follows:
content
is the content of the message.
receiver_hash
must be the ID of the target user, not url token.
machine.action('Me','SendMessage', '', _data={'content':..., 'receiver_hash':...})
Set Gender (设置性别)¶
You need to pass additional information as follows:
gender
is an integer. 0 for female, 1 for male, and -1 for not set.
machine.action('Me','SetGender', '', _data={'gender':...})
Set Headline (设置一句话介绍)¶
You need to pass additional information as follows:
headline
is a string containing the introduction.
machine.action('Me','SetHeadline', '', _data={'headline':...})
Set Locations (设置居住地)¶
You need to pass additional information as follows:
locations
is a list of strings, for example, ['province_name', 'city_name']
machine.action('Me','SetLocations', '', _data={'locations':...})
Set Business (设置从事行业)¶
You need to pass additional information as follows:
business
is a string, and it must be from the available options in the list, otherwise it will
fail silently. Please refer to Zhihu for the complete list.
machine.action('Me','SetBusiness', '', _data={'business':...})
Set Employments (设置职业经历)¶
You need to pass additional information as follows:
employments
is a list of dictionaries. [{'job':'job_name', 'company':'company_name'},...]
machine.action('Me','SetEmployments', '', _data={'employments':...})
Set Educations (设置教育经历)¶
You need to pass additional information as follows:
educations
is a list of dictionaries. [{'major':'major_name', 'school':'school_name'}]
machine.action('Me','SetEducations', '', _data={'educations':...})
Set Description (设置个人简介)¶
You need to pass additional information as follows:
description
is a string. The content should be wrapped with <p>xxxxx</p>
.
machine.action('Me','SetDescription', '', _data={'description':...})
Add Question (提问)¶
You need to pass additional information as follows:
title
is a string containing the title.
topic_url_tokens
is a list of topic IDs.
detail
is a string containing the description.
is_anonymous
is a boolean.
machine.action('Me','AddQuestion', '', _data={'title':..., 'topic_url_tokens':..., 'detail':..., 'is_anonymous':...})
Add Pin (发布想法)¶
You need to pass additional information as follows:
content
should be of form json.dumps([{'type':'text','content':'<p>xxxxxxx</p>'}])
, where ‘xxxx’ is your pin content.
machine.action('Me','AddPin', '', _data={'content':...})
Create Favorite List (创建收藏夹)¶
You need to pass additional information as follows:
title
is a string containing the title.
description
is a string containing the description.
is_public
is a boolean.
machine.action('Me','CreateFavlist', '', _data={'title':..., 'description':..., 'is_public':...})
Report (举报)¶
You need to pass additional information as follows:
resource_id
is the ID of the content to report.
type
is a string, should be one of ['answer', 'question', 'pin', 'article', 'comment', 'member']
custom_reason
is a string containing the description when applicable, empty string otherwise.
reason_type
is a string. It has different sets of options for each category as listed. The items with (custom) means
that it requires a custom description. The “old” option corresponds to “others” in the visible list.
Questions: | ambiguity, subjective, rumour, abuse, provoke, medicine, personal, superstition, spam (custom), politics, porn, suicide, illegality (custom), old (custom). |
---|---|
Answers and Articles: | |
spam (custom), abuse, unfriendly (custom), politics,porn, untruth (custom), suicide, illegality (custom), repost (custom), temptation (custom), old (custom). | |
Pins and Comments: | |
spam (custom), abuse, unfriendly (custom), politics, porn, untruth (custom), suicide, illegality (custom), old (custom). | |
Members: | impersonate (custom), spam, profile (custom), old (custom). |
Note: Reporting favorite lists is not included because it uses the old API.
machine.action('Me','Report', '', _data={'resource_id':..., 'type':..., 'reason_type':..., 'custom_reason':...})
Members¶
Follow a User (关注用户)¶
machine.action('Members','Follow', user_url_token)
Unfollow a User (取消关注用户)¶
machine.action('Members','Unfollow', user_url_token)
Block a User (屏蔽用户)¶
machine.action('Members','Block', user_url_token)
Unblock a User (取消屏蔽用户)¶
machine.action('Members','Unblock', user_url_token)
Questions¶
Edit Topics (修改问题话题)¶
You need to pass additional information as follows:
question
is a dict of format {'topic_url_tokens':['topic_id1','topic_id2']}
.
machine.action('Questions','EditTopics', question_id, _data={'question':...})
Edit Title (修改问题标题)¶
You need to pass additional information as follows:
question
is a dict of format {'title':'title_of_question'}
.
meta
is a dict of format {'reason':'标点或格式错误'}
.
machine.action('Questions','EditTitle', question_id, _data={'question':..., 'meta':...})
Edit Content (修改问题补充说明)¶
You need to pass additional information as follows:
question
is a dict of format {'title':'title_of_question', 'detail':'content_of_question'}
.
meta
is a dict of format {'reason':'标点或格式错误'}
.
machine.action('Questions','EditContent', question_id, _data={'question':..., 'meta':...})
Add Comment (评论问题)¶
You need to pass additional information as follows:
content
is a string containing the comment.
reply_to_id
(optional) is a comment ID that you wish to reply to.
machine.action('Questions','AddComment', question_id, _data={'content':...})
Invite (邀请)¶
You need to pass additional information as follows:
member_hash
is the user hash of the invitee.
machine.action('Questions','Invite', question_id, _data={'member_hash':...})
Anonymize (启用匿名)¶
machine.action('Questions','Anonymize', question_id)
Deanonymize (取消匿名)¶
machine.action('Questions','Deanonymize', question_id)
Add Answer (添加回答)¶
You need to pass additional information as follows:
content
is a string containing the answer. The content should be wrapped with <p>xxxxx</p>
.
reshipment_settings
is a string. Its value should be one of ['disallowed','allowed','need_payment']
.
comment_permission
is a string. Its value should be one of ['all','censor','followee', or 'nobody']
.
machine.action('Questions','AddAnswer', question_id, _data={'content':..., 'reshipment_settings':..., 'comment_permission':...})
Delete Question (删除问题)¶
machine.action('Questions','DeleteQuestion', question_id)
Follow Question (关注问题)¶
machine.action('Questions','FollowQuestion', question_id)
Unfollow Question (取消关注问题)¶
machine.action('Questions','UnfollowQuestion', question_id)
Answers¶
Vote Up (点赞回答)¶
machine.action('Answers','VoteUp', answer_id)
Cancel Vote (取消点赞/反对回答)¶
machine.action('Answers','CancelVote', answer_id)
Vote Down (反对回答)¶
machine.action('Answers','VoteDown', answer_id)
Add Comment (评论回答)¶
You need to pass additional information as follows:
content
is a string containing the comment.
machine.action('Answers','AddComment', answer_id, _data={'content':...})
Thank (感谢回答)¶
machine.action('Answers','Thank', answer_id)
Undo Thank (取消感谢回答)¶
machine.action('Answers','UndoThank', answer_id)
Mark Unhelpful (没有帮助)¶
machine.action('Answers','MarkUnhelpful', answer_id)
Undo Mark Unhelpful (取消没有帮助)¶
machine.action('Answers','UndoMarkUnhelpful', answer_id)
Set Comment Permission (修改回答评论权限)¶
You need to pass additional information as follows:
comment_permission
is a string. Its value should be one of ['all','censor','followee', or 'nobody']
.
machine.action('Answers','SetCommentPermission', answer_id, _data={'comment_permission':...})
Set Reshipment Permission (修改回答转载设置)¶
You need to pass additional information as follows:
reshipment_settings
is a string. Its value should be one of ['disallowed','allowed','need_payment']
.
machine.action('Answers','SetReshipmentPermission', answer_id, _data={'reshipment_settings':...})
Edit Answer (修改回答)¶
You need to pass additional information as follows:
content
is a string containing the answer. The content should be wrapped with <p>xxxxx</p>
.
machine.action('Answers','EditAnswer', answer_id, _data={'content':...})
Delete Answer (删除回答)¶
machine.action('Answers','DeleteAnswer', answer_id)
Restore Answer (撤销删除回答)¶
machine.action('Answers','RestoreAnswer', answer_id)
Comments¶
Delete Comment (删除评论)¶
machine.action('Comments','DeleteComment', comment_id)
Like (点赞评论)¶
machine.action('Comments','LikeComment', comment_id)
Undo Like (取消点赞评论)¶
machine.action('Comments','UndoLikeComment', comment_id)
Dislike (踩评论)¶
machine.action('Comments','DislikeComment', comment_id)
Undo Dislike (取消踩评论)¶
machine.action('Comments','UndoDislikeComment', comment_id)
Feature (设为推荐评论)¶
machine.action('Comments','Feature', comment_id)
Undo Feature (取消推荐评论)¶
machine.action('Comments','UndoFeature', comment_id)
Collapse (折叠评论)¶
machine.action('Comments','Collapse', comment_id)
Undo Collapse (取消折叠评论)¶
machine.action('Comments','UndoCollapse', comment_id)
Pins¶
Add Comment (评论想法)¶
You need to pass additional information as follows:
content
is a string containing the comment.
reply_to_id
(optional) is a comment ID that you wish to reply to.
machine.action('Pins','AddComment', pin_id, _data={'content':...})
Like (鼓掌想法)¶
machine.action('Pins','Like', pin_id)
Undo Like (取消鼓掌想法)¶
machine.action('Pins','UndoLike', pin_id)
Delete Pin (删除想法)¶
machine.action('Pins','DeletePin', pin_id)
Topics¶
Follow Topic (关注话题)¶
machine.action('Topics','FollowTopic', topic_id)
Unfollow Topic (取消关注话题)¶
machine.action('Topics','UnfollowTopic', topic_id)
Favorite Lists¶
Favorite Lists Add Entry (收藏回答/文章/想法)¶
You need to pass additional information as follows:
content_id
is the ID of the answer/article/pin.
content_type
is a string, it should be one of ['answer', 'pin' or 'article']
.
machine.action('Favlists','AddEntry', favlist_id, _data={'content_id':..., 'content_type':...})
Add Comment (评论收藏夹)¶
You need to pass additional information as follows:
content
is a string containing the comment.
reply_to_id
(optional) is a comment ID that you wish to reply to.
machine.action('Favlists','AddComment', favlist_id, _data={'content':...})
Follow Favorite List (关注收藏夹)¶
You need to pass additional information as follows:
favlist_id
is the ID of the favorite list.
Please note that this inconsistency is caused by version difference of Zhihu API. This action uses the old form version instead of v4 API.
machine.action('Favlists','FollowFavlist', '', _data={'favlist_id':...})
Columns¶
Follow Column (关注专栏)¶
machine.action('Columns','FollowColumn', column_id)
Unfollow Column (取消关注专栏)¶
machine.action('Columns','UnfollowColumn', column_id)
Articles¶
Add Comment (评论文章)¶
You need to pass additional information as follows:
content
is a string containing the comment.
reply_to_id
(optional) is a comment ID that you wish to reply to.
machine.action('Articles','AddComment', article_id, _data={'content':...})
Set Comment Permission (修改文章评论权限)¶
You need to pass additional information as follows:
comment_permission
is a string. Its value should be one of ['all','censor','followee', or 'nobody']
.
machine.action('Articles','SetCommentPermission', article_id, _data={'comment_permission':...})
Delete Article (删除文章)¶
machine.action('Articles','DeleteArticle', article_id)
Vote Up (点赞文章)¶
machine.action('Articles','VoteUp', article_id)
Cancel Vote (取消点赞文章)¶
machine.action('Articles','CancelVote', article_id)