탐색으로 건너뛰기

How do I separate WeChat headline articles from secondary positions in a saved account list?

To tell a headline from a secondary article, read idx from the article list returned by wechat_mp.v2.fetch_account_articles: 1 is the headline article of the publication batch, 2 is the second article, and higher values are later positions. Filter idx=1 to study the first article of each push, or keep every position to examine whole batches.

Why isn’t the first row of a result page necessarily a headline?

A result page can contain several publication batches or begin partway through one batch. Placement is the article’s position within the article’s publication batch, not the article’s row on the current page.

For example, two batches on one page:

BatchidxExample titlePlacement
A1New product launchHeadline
A2How to use the new productSecondary, position 2
B1This week’s interviewHeadline

Filtering yields two headlines and one secondary article. Keep both batch A records even though the two records share app_msg_id: article identity combines account, app_msg_id and idx.

Collect a headline-only reading list

  1. Retrieve the verified account’s article list, selecting the article tab and raw:false.
  2. Read data.articles[].idx and keep the articles with position 1, with title, original link and publication time.
  3. Save articles with positions above 1 separately for comparison, and mark records without a position as pending review.

Reuse saved list responses; do not request every body only to determine placement, because the list’s idx field already gives the placement. If you start from one article URL, use the article-to-account handoff to find the account, then locate the article in the account’s list.

To hand the task to an assistant connected to BeatAPI, use this instruction:

Organize the latest three list pages of the target account. Keep headline articles with title, link and publication time, save secondary articles separately and flag records with missing positions. Report the actual number of headlines collected.

Read the files that article_positions.py exports

article_positions.py (in the last section) splits saved list pages into four files:

  • headlines.csv: position 1.
  • secondary.csv: later articles with their exact positions.
  • unknown-position.json: records without a returned position.
  • coverage.json: page sources, observed article distribution and counts.

If a batch shows only position 2, keep the position 2 record and revisit the list when you need the batch’s first article. For engagement research, group headlines and secondary articles first, then compare publication time and subject. Continue with statistics for selected articles. Retrieval prices are on the pricing page.

Optional export from saved lists

Retrieve the lists with data:wechat_mp.v2.fetch_account_articles; article_positions.py then filters the saved responses locally.

article_positions.py accepts 1–20 saved article-tab pages of the same canonical gh_ account, requested with raw:false. Record the actual requests, times and files in the manifest; each later page uses the previous response’s next_offset.

Replace the history-pages.json example below with your own records:

[
{"file":"articles-page-1.json","action":"wechat_mp.v2.fetch_account_articles","http_status":200,"collected_at":"2026-11-16T10:00:00Z","params":{"username":"gh_example","raw":false,"item_show_type":0}}
]

Save the code as article_positions.py, then run:

python3 article_positions.py history-pages.json position-review
import csv, datetime, hashlib, json, pathlib, re, sys
manifest=pathlib.Path(sys.argv[1]);manifest_bytes=manifest.read_bytes();pages=json.loads(manifest_bytes)
if not isinstance(pages,list) or not 1<=len(pages)<=20: raise ValueError('Use 1..20 saved article-list pages')
ACTION='wechat_mp.v2.fetch_account_articles'
rows,unknown,seen,requests,archives,sources=[],[],{},set(),[],[]
account=None;next_offset=None;last_time=None;used_offsets=set()
def identifier(value):
if type(value) is int and 1<=value<=9007199254740991:return str(value)
if isinstance(value,str) and re.fullmatch(r'[0-9]+',value) and int(value)>0:return str(int(value))
raise ValueError('Use original positive digit strings or safe integers')
for page_index,page in enumerate(pages):
params=page['params'];username=params.get('username')
if not isinstance(username,str) or not re.fullmatch(r'gh_[A-Za-z0-9_]+',username):raise ValueError('Use the canonical account username')
if account is None:account=username
if username!=account or params.get('raw') is not False or type(params.get('item_show_type')) is not int or params['item_show_type']!=0:raise ValueError('Same account, explicit raw=false and article tab 0 required')
if page_index and (not isinstance(next_offset,str) or not next_offset or params.get('offset')!=next_offset):raise ValueError('Saved pages do not follow the previous cursor')
offset=params.get('offset','')
if not isinstance(offset,str) or offset in used_offsets:raise ValueError('Repeated or invalid requested cursor')
used_offsets.add(offset)
time=datetime.datetime.fromisoformat(page['collected_at'].replace('Z','+00:00'))
if time.utcoffset() is None or (last_time is not None and time<last_time):raise ValueError('Use ordered actual collection times with timezone')
last_time=time
if page.get('action')!=ACTION or type(page.get('http_status')) is not int or page['http_status']!=200:raise ValueError('Expected successful recorded article-list request')
raw=(manifest.parent/page['file']).read_bytes();response=json.loads(raw)
rid=response.get('request_id')
if not isinstance(rid,str) or not rid.strip() or rid in requests:raise ValueError('Missing/repeated request ID')
requests.add(rid)
if response.get('status')!='succeeded' or response.get('error') is not None or response.get('action')!=ACTION:raise ValueError('Failed or wrong response')
data=response['data']
if data.get('biz_username')!=account or not isinstance(data.get('articles'),list):raise ValueError('Wrong account or simplified article shape missing')
if type(data.get('is_end')) is not int or data['is_end'] not in (0,1):raise ValueError('Invalid end marker')
next_offset=None if data['is_end']==1 else data.get('next_offset')
if next_offset is not None and (not isinstance(next_offset,str) or not next_offset or next_offset in used_offsets):raise ValueError('Repeated or invalid continuation cursor')
name='raw-'+str(page_index+1).zfill(3)+'.json';digest=hashlib.sha256(raw).hexdigest();archives.append((name,raw));sources.append({'file':name,'sha256':digest,'request_id':rid,'collected_at':page['collected_at']})
for position,article in enumerate(data['articles'],1):
if not isinstance(article,dict):raise ValueError('Unreadable article object')
appid=identifier(article.get('app_msg_id'))
idx=None if article.get('idx') is None else int(identifier(article['idx']))
values={k:article.get(k) for k in ['title','url','create_time']}
if values['title'] is not None and not isinstance(values['title'],str):raise ValueError('Invalid title')
if values['url'] is not None and not isinstance(values['url'],str):raise ValueError('Invalid article URL field')
published=values['create_time']
if published is not None and not ((type(published) is int and 0<=published<=9007199254740991) or (isinstance(published,str) and re.fullmatch(r'[0-9]+',published))):raise ValueError('Invalid raw publication timestamp')
row={'account':account,'app_msg_id':appid,'idx':idx,'placement':'unknown' if idx is None else 'headline' if idx==1 else 'secondary',
**values,'request_id':rid,'collected_at':page['collected_at'],'source_file':name,'source_sha256':digest,'item_position_on_page':position}
if idx is None:unknown.append(row);continue
key=(appid,idx)
if key in seen:
if any(seen[key][k]!=row[k] for k in values):raise ValueError('Conflicting duplicate article metadata; split observations for review')
continue
seen[key]=row;rows.append(row)
out=pathlib.Path(sys.argv[2]);out.mkdir()
for name,raw in archives:(out/name).write_bytes(raw)
(out/'input-manifest.json').write_bytes(manifest_bytes)
for name,value in [('articles.json',rows),('unknown-position.json',unknown),('coverage.json',{'account':account,
'known_position_articles':len(rows),'headlines':sum(r['idx']==1 for r in rows),'secondary_articles':sum(r['idx']>1 for r in rows),
'unknown_position_observations':len(unknown),'sources':sources,'manifest_sha256':hashlib.sha256(manifest_bytes).hexdigest(),
'observed_groups':[{'app_msg_id':appid,'positions':sorted(r['idx'] for r in rows if r['app_msg_id']==appid),'complete_group_verified':False} for appid in sorted({r['app_msg_id'] for r in rows})],
'complete_history':False,'executed_calls':0})]:
(out/name).write_text(json.dumps(value,ensure_ascii=False,indent=2),encoding='utf-8')
fields=['account','app_msg_id','idx','placement','title','url','create_time','collected_at','request_id','source_file','source_sha256']
for filename,selected in [('headlines.csv',[r for r in rows if r['idx']==1]),('secondary.csv',[r for r in rows if r['idx']>1])]:
with (out/filename).open('w',encoding='utf-8-sig',newline='') as f:
w=csv.DictWriter(f,fieldnames=fields);w.writeheader()
for row in selected:
cells={k:'' if row[k] is None else str(row[k]) for k in fields};w.writerow({k:"'"+v if v.lstrip().startswith(('=','+','-','@')) else v for k,v in cells.items()})
print(json.dumps({'headlines':sum(r['idx']==1 for r in rows),'secondary':sum(r['idx']>1 for r in rows),'unknown':len(unknown),'executed_calls':0}))