탐색으로 건너뛰기

How do I export Channels comments and organize recurring viewer questions?

Fetch a video’s visible comments with wechat_channels.v2.fetch_video_comments and the video’s numeric ID, save each response, then export the saved responses to comment-observations.csv with export_channel_comments.py. Leave comment_id empty for top-level comments. To read the replies to one comment, pass that parent comment’s comment_id and start at page one of the parent’s reply thread.

For example, for an event-introduction video, you might investigate viewer questions about tickets, reservations and admission. Find the specific questions, check whether the video already answers each question, then decide what to add to the FAQ or the video description.

Start with one video

  1. Confirm the target video. Reuse the video’s numeric ID. With only a share link, follow the link and identifier workflow to confirm the video and the account.
  2. Retrieve root comments. Start with at most three pages, and save the text, the returned like counts, the times and the sources. Plan another batch when the research needs broader coverage.
  3. Expand replies that change the meaning. A comment such as “Does this also need a reservation?” may refer to a specific activity. Read that parent comment’s replies and keep the parent–reply relationship.
  4. Organize the questions. Keep each commenter’s original wording separate from your summary. Check the video’s own explanation, then mark the next action: cite an existing answer, add an explanation or verify a detail.

For an assistant connected to BeatAPI:

Read at most three comment pages for this event video. Organize questions about ticket price, reservations and admission. Keep original wording and sources, and inspect replies when context requires them. Export the source table and list questions worth adding to the FAQ.

Turn comments into useful FAQ leads

ObservationRecordNext action
Several comments ask about the same booking stepGroup the question while keeping each source excerptCheck the video and clarify the step or destination
Someone reports that no reservation was needed last timeLabel the report as the commenter’s experience, with its time contextCheck the current event’s rules before using the report
A reply adds that children need separate bookingsKeep the reply with its parent commentVerify the rule and consider a clarification
Emojis, praise or unrelated discussionKeep in the source table and exclude from the question reviewDo not invent a requirement

Comments with similar wording may belong to one theme, but the same comment returned twice stays one source. Describe the question records you actually reviewed; a three-page sample does not represent every viewer.

Read the export

comment-observations.csv holds one observation per row. coverage.json records the video, the parent branch, the pages actually read and the stop reason. Review the comment text first, then select reply parents from the original response. prepare_reply_branch.py (later on this page) prepares a reply-branch request from the saved response, so you never copy a long ID that spreadsheet software may have altered.

comment-observations.csv omits the nickname, avatar and location profile columns, so the review stays on the questions. Before sharing, check the comment text for personal details that commenters disclosed themselves, and store the raw responses separately from the working table.

The sections below cover retrieval, saved pages and local export. Each run of export_channel_comments.py processes one branch of one video.

Select the root branch or one reply branch

Both branches use data:wechat_channels.v2.fetch_video_comments:

  • For root comments, set comment_id="".
  • For replies, set comment_id to the selected parent’s exact comment_id.

The root branch and the reply branch are one action with different scope, not a separate reply endpoint. Reset last_buffer to "" at the start of each branch, and set raw:false explicitly. The response contains data.object_id, comment_id, comments, down_continue and last_buffer. Each comment has comment_id and content, and optionally like_count, reply_count and create_time. A reply_count value counts replies; the value is not a collected reply.

A root-page request looks like the body below. Sending the request needs its own approval; the exporter further down runs offline.

{"action":"wechat_channels.v2.fetch_video_comments","params":{"object_id":"14941130915890399732","comment_id":"","last_buffer":"","raw":false}}

Save full responses and export one branch

  1. Create comment-pages.json. Paths in comment-pages.json are relative to the manifest file. For each later page, pass the actual last_buffer from the preceding page, not a page number, and keep object_id, comment_id and raw unchanged. Save the actual HTTP status and the collection time of every page, including a final failed response. Do not fabricate a JSON response for a transport timeout.
[{"action":"wechat_channels.v2.fetch_video_comments","params":{"object_id":"14941130915890399732","comment_id":"","last_buffer":"","raw":false},"http_status":200,"collected_at":"2026-11-17T09:00:00Z","response_file":"root-1.json"}]
  1. Save the script below as export_channel_comments.py and run python3 export_channel_comments.py comment-pages.json root-review.
  2. For a selected parent’s replies, use a separate manifest and a separate output directory, such as reply-123-review. Never mix root pages and reply pages in one chain.

export_channel_comments.py checks the returned object_id and parent identity. If the returned echo is unsafe or does not match, export_channel_comments.py stops before creating output instead of trusting a possibly rounded identifier.

import csv,hashlib,json,pathlib,re,sys
from datetime import datetime
manifest,out=map(pathlib.Path,sys.argv[1:3]);original=manifest.read_bytes();pages=json.loads(original)
if not isinstance(pages,list) or not 1<=len(pages)<=3:raise ValueError('Supply 1–3 saved pages for one branch')
ACTION='wechat_channels.v2.fetch_video_comments';rows,sources,ids,rids,cursors=[],[],set(),set(),set();expected='';account=None;parent=None;stop=None;unsafe=0
def cell(v):
if v is None:return ''
v=str(v);return "'"+v if v.startswith(('=','+','-','@','\t','\r','\n')) else v
def identity(v):
if isinstance(v,str) and re.fullmatch(r'[0-9]{1,32}',v):return v,'string'
if type(v) is int and 0<=v<=9007199254740991:return str(v),'safe_integer'
return None,'unsafe_or_invalid'
for i,e in enumerate(pages,1):
if stop is not None:raise ValueError('Pages supplied after stop condition')
params=e.get('params');u=params.get('object_id') if isinstance(params,dict) else None
if e.get('action')!=ACTION or not isinstance(params,dict) or set(params)!={'object_id','comment_id','raw','last_buffer'} or params['raw'] is not False:raise ValueError('Use exact raw:false list request')
if not isinstance(u,str) or not re.fullmatch(r'[0-9]{1,32}',u):raise ValueError('Invalid object ID string')
branch=params['comment_id']
if not isinstance(branch,str) or not re.fullmatch(r'[0-9]{0,32}',branch):raise ValueError('Invalid parent ID string')
if account is None:account,parent=u,branch
if u!=account or branch!=parent or params['last_buffer']!=expected:raise ValueError('Account or cursor chain changed')
cursors.add(expected)
t=e.get('collected_at')
if not isinstance(t,str) or datetime.fromisoformat(t.replace('Z','+00:00')).tzinfo is None:raise ValueError('Record actual collection time with timezone')
http=e.get('http_status')
if type(http) is not int or not 100<=http<=599:raise ValueError('Invalid HTTP status')
raw=(manifest.parent/e['response_file']).read_bytes();body=json.loads(raw)
if not isinstance(body,dict):raise ValueError('Expected response object')
source={'index':i,'request':e,'sha256':hashlib.sha256(raw).hexdigest(),'raw_file':'raw-%02d.json'%i};sources.append((source,raw))
if http!=200:
error=body.get('error')
if not isinstance(error,dict) or not isinstance(error.get('code'),str) or not error['code'].strip():raise ValueError('Expected gateway error')
source.update(error_code=error['code'],request_id=error.get('request_id'));stop='gateway_failed';continue
data=body.get('data');rid=body.get('request_id')
if body.get('status')!='succeeded' or body.get('action')!=ACTION or body.get('error') is not None or not isinstance(data,dict):raise ValueError('Wrong successful envelope')
if not isinstance(rid,str) or not rid.strip() or rid in rids:raise ValueError('Missing or duplicate request ID')
rids.add(rid);source['request_id']=rid
echo,_=identity(data.get('object_id'));parent_echo,_=identity(data.get('comment_id'))
if echo!=account or (parent and parent_echo!=parent) or (not parent and data.get('comment_id') not in (None,'')) or not isinstance(data.get('comments'),list):raise ValueError('Missing, unsafe or mismatched object/parent echo or comments array')
videos=data['comments'];source['reported_count']=data.get('count');source['observations']=len(videos)
for j,v in enumerate(videos):
if not isinstance(v,dict):raise ValueError('Invalid comment object')
object_id,state=identity(v.get('comment_id'));duplicate=object_id in ids if object_id is not None else False
if object_id is None:unsafe+=1
else:ids.add(object_id)
row={'object_id':account,'parent_id':parent,'comment_id':object_id,'id_state':state,'id_raw':json.dumps(v.get('comment_id')),'duplicate_observation':str(duplicate).lower(),'content':v.get('content'),'content_present':str('content' in v).lower(),'collected_at':t,'request_id':rid,'source_index':i,'comment_index':j}
if row['content'] is not None and not isinstance(row['content'],str):raise ValueError('Invalid comment text')
for field in ['create_time','like_count','reply_count']:
row[field+'_raw']=json.dumps(v.get(field),ensure_ascii=False);row[field+'_present']=str(field in v).lower()
rows.append(row)
flag=data.get('down_continue');cursor=data.get('last_buffer');source.update(down_continue=flag,last_buffer=cursor)
if type(flag) not in (bool,int) or flag not in (0,1):stop='unsupported_more_flag'
elif not flag:stop='provider_end'
elif not videos:stop='empty_page_with_more'
elif not isinstance(cursor,str) or not cursor or not re.fullmatch(r'[A-Za-z0-9+/=_-]+',cursor):stop='missing_or_invalid_cursor'
elif cursor in cursors:stop='repeated_cursor'
else:expected=cursor
if stop is None:stop='saved_page_limit'
columns=['object_id','parent_id','comment_id','id_state','id_raw','duplicate_observation','content','content_present','collected_at','request_id','source_index','comment_index']
for field in ['create_time','like_count','reply_count']:columns.extend([field+'_raw',field+'_present'])
out.mkdir(mode=0o700,exist_ok=False)
with (out/'comment-observations.csv').open('x',encoding='utf-8-sig',newline='') as f:
w=csv.DictWriter(f,fieldnames=columns);w.writeheader();w.writerows({k:cell(v) for k,v in r.items()} for r in rows)
for source,raw in sources:(out/source['raw_file']).write_bytes(raw)
(out/'manifest.json').write_bytes(original)
report={'object_id':account,'parent_id':parent,'sources':[s for s,_ in sources],'stop_reason':stop,'comment_observations':len(rows),'distinct_usable_ids':len(ids),'unsafe_id_observations':unsafe,'provider_end_seen':stop=='provider_end','all_comments_verified':False,'author_profile_fields_exported':False,'executed_calls':0,'manifest_sha256':hashlib.sha256(original).hexdigest()}
(out/'coverage.json').write_text(json.dumps(report,ensure_ascii=False,indent=2),encoding='utf-8')
if stop=='saved_page_limit':(out/'unexecuted-next-request.json').write_text(json.dumps({'action':ACTION,'params':{'object_id':account,'comment_id':parent,'raw':False,'last_buffer':expected}},indent=2),encoding='utf-8')
print(json.dumps({'observations':len(rows),'stop_reason':stop,'executed_calls':0}))

Accept the table, not just a successful HTTP response

  • One CSV row is one observation. export_channel_comments.py flags duplicate usable comment IDs instead of silently replacing the earlier row, and keeps missing and null counts distinguishable. A duplicate comment is not a second independent opinion.
  • A row with an unsafe comment ID has no usable comment_id. You can still review the row’s text by its source_index and comment_index, but the row cannot safely drive a reply request. Do not repair an unsafe ID by casting a rounded number to text.
  • provider_end means only that the current branch reached the provider’s reported end. A finished root branch does not finish any reply branch. Budget exhaustion, a repeated or missing cursor, an empty page that still reports more, and unsupported flags are separate stop reasons.
  • A final gateway error keeps the earlier comments and the error evidence. A mixed object or parent, a bad schema or a broken cursor chain rejects the whole batch. export_channel_comments.py never overwrites existing output; treat an output directory whose writing was interrupted as incomplete.
  • The CSV deliberately leaves out the nickname, username, avatar and IP-region fields. Comment text can still identify people, so removing profile columns is not anonymization. Review and redact a separate copy for sharing, and keep the originals only in the private local evidence directory. The scripts do not upload or notify anywhere.

Budget the review before collecting

For example, three root pages plus one reply page for each of two selected parents is at most five planned comment-page requests. Estimate the five requests with current pricing. Finding the video and any extra pages are separate requests; the actual number of comments depends on the responses. Exporting and reviewing saved material locally needs no new retrieval.

Read the exported text and choose a few questions or complaints worth checking; keep the source row next to each quoted example. A bounded sample does not support claims about sentiment, representativeness, unique users or all public discussion. A selected reply branch can add context, but the saved reply request must name the exact safe parent taken from the root evidence.

Before exporting, check the comment fields and cursor fields against your saved response. The examples on this page use synthetic records.

Select a reply parent from the saved root evidence, not from a copied spreadsheet ID

  1. In the root export, choose the parent’s source_index (one-based page number) and comment_index (zero-based row in the original comments array).
  2. Save the script below as prepare_reply_branch.py and run python3 prepare_reply_branch.py root-review 1 0 selected-parent. Inspect the exact source comment first; do not pick a parent automatically by title, author name or largest reply_count.
  3. prepare_reply_branch.py rereads the archived response and checks the response’s hash, action, root scope and identity. prepare_reply_branch.py does not trust an edited comment ID in the CSV: a safe integer or an original digit string is accepted, and an unsafe numeric parent stops before output. reply_count is not treated as proof that replies are currently available.
  4. prepare_reply_branch.py writes an unexecuted reply request and the local parent provenance into the new directory selected-parent.
import hashlib,json,pathlib,re,sys
root=pathlib.Path(sys.argv[1]);source_index=int(sys.argv[2]);comment_index=int(sys.argv[3]);out=pathlib.Path(sys.argv[4])
report_bytes=(root/'coverage.json').read_bytes();report=json.loads(report_bytes)
if report.get('parent_id')!='' or not isinstance(report.get('sources'),list):raise ValueError('Choose a root-comment export, not an existing reply branch')
obj=report.get('object_id')
if not isinstance(obj,str) or not re.fullmatch(r'[0-9]{1,32}',obj):raise ValueError('Invalid recorded object ID')
if not 1<=source_index<=len(report['sources']) or comment_index<0:raise ValueError('Choose the exact source_index and zero-based comment_index')
source=report['sources'][source_index-1];request=source.get('request');params=request.get('params') if isinstance(request,dict) else None
if source.get('index')!=source_index or not isinstance(params,dict) or request.get('action')!='wechat_channels.v2.fetch_video_comments' or params.get('object_id')!=obj or params.get('comment_id')!='' or params.get('raw') is not False or request.get('http_status')!=200:raise ValueError('Selected source is not a successful root request')
raw=(root/('raw-%02d.json'%source_index)).read_bytes()
if source.get('sha256')!=hashlib.sha256(raw).hexdigest():raise ValueError('Root raw source changed')
body=json.loads(raw);data=body.get('data')
if body.get('status')!='succeeded' or body.get('action')!=request['action'] or body.get('error') is not None or body.get('request_id')!=source.get('request_id') or not isinstance(body.get('request_id'),str) or not body['request_id'].strip() or not isinstance(data,dict):raise ValueError('Invalid root response')
def identifier(value):
if isinstance(value,str) and re.fullmatch(r'[0-9]{1,32}',value):return value
if type(value) is int and 0<=value<=9007199254740991:return str(value)
raise ValueError('Unsafe or missing identifier; do not stringify rounded IDs')
if identifier(data.get('object_id'))!=obj or data.get('comment_id') not in (None,''):raise ValueError('Root identity mismatch')
comments=data.get('comments')
if not isinstance(comments,list) or comment_index>=len(comments) or not isinstance(comments[comment_index],dict):raise ValueError('Comment source position missing')
parent=identifier(comments[comment_index].get('comment_id'))
request={'action':'wechat_channels.v2.fetch_video_comments','params':{'object_id':obj,'comment_id':parent,'last_buffer':'','raw':False}}
out.mkdir(mode=0o700,exist_ok=False)
(out/'unexecuted-reply-request.json').write_text(json.dumps(request,indent=2),encoding='utf-8')
(out/'parent-evidence.json').write_text(json.dumps({'object_id':obj,'parent_id':parent,'root_request_id':body['request_id'],'source_index':source_index,'comment_index':comment_index,'raw_sha256':hashlib.sha256(raw).hexdigest(),'coverage_sha256':hashlib.sha256(report_bytes).hexdigest(),'executed_calls':0,'root_export_path':str(root),'identity_basis':'selected stored root observation; not live availability or legal identity'},indent=2),encoding='utf-8')
print(json.dumps({'parent_id':parent,'executed_calls':0}))

After separately approved collection, record the exact object_id and comment_id with the actual response and time in a new reply manifest that starts with last_buffer="". Run export_channel_comments.py into a separate reply directory and keep selected-parent beside the reply directory. selected-parent links the branch decision back to a recorded root page; selected-parent does not mean the reply page was already fetched. The root evidence hashes verify local bytes, not network authenticity, so do not edit both a source file and its metadata to get past a check. Neither script makes calls, retries or expands branches automatically.