跳到导航

研究同行 X 内容,怎么分清自己发布、引用、回复和转推?

要看一个 X 账号自己写的帖子,先用 twitter.web.fetch_user_post_tweet 取这个账号的时间线,再保留作者 ID 与目标账号一致、且没有 retweeted_tweet 转推对象的记录。目标账号写的回复和引用帖按需要保留,审核时按保存的原帖逐行标注类型。

先决定几类内容在研究里怎么用

内容情况对研究有什么意义应该怎么处理
目标账号自己写的产品帖子可研究目标账号的表达、功能和活动保留原句和来源,再人工判断是否与研究问题相关。
目标账号写了自己的引用说明有目标账号自己的表达,也引用了别人的内容筛选器可能保留这条引用帖;分析时把本人的说明与被引用原作分开。
目标账号回复别人可以看到补充条件或沟通方式保留并标注回复角色;不当作独立的主公告,必要时补父上下文。
目标账号转推别人原作说明这次转发行为,不等于本人创作在本子集排除,原始观察仍留档供核查。
作者缺失或与目标ID不符归属不够明确不进入确认子集,不猜作者。

“被转推了很多次”与“这条本身是一条转推”不是一件事。点赞、转推、引用次数都是互动计数,不能靠数值大于0判断帖子类型。

什么条件下,才值得用严格筛选?

你已有独立核实的账号 ID,并且要避免把其他作者混入结论时,使用下文的 own_posts.py。只有 handle、没有可信 ID 时,先用账号变化观察保留来源和未知项,不要把观察结果说成严格的作者认证。账号身份变化后要重新核对。

own_posts.py 不会自动识别未知账号,也不证明所给证据以外的内容归属。已存响应意外缺少转推标记时,脚本无法独立认证这一行的真实类型。own_posts.py 的准确表述是“已存响应中作者匹配且没有转推对象”。

交付时,怎么让同事看懂保留和排除?

交付 selected-posts.csv/JSON 作为候选,连同记录排除项和未知项的 observations.json 一起交。另写一段范围说明:哪个账号、哪几页、什么时间观察、保留了哪些类型、哪些条件无法确认。一张看起来干净的表,不能证明包含了账号发过的全部原创帖子。

“最近两周”“互动前三”这类需求要另定日期和指标规则,own_posts.py 不做日期筛选或互动排名。只研究产品公告时,人工排除不相关的回复和其他内容,并记录每条理由;作者匹配不等于业务相关性审核。

下面几节依次说明账号身份、输入清单和原始页筛选。优先复用已保存页:本地筛选不发起调用,不取下一页,也不发布任何内容。

用本产品的账号路线,不搬其他服务的tab

先 Inspect data:twitter.web.fetch_user_post_tweet。当前输入是 screen_name 或整数 rest_id,加可选的 cursor;两种身份都发时,rest_id 优先。twitter.web.fetch_user_post_tweet 没有 tab 参数,不能传 tab=posts/replies/media。data.timeline 是当前页,data.next_cursor 用于续页,data.pinned 单独保存。

文档说明 retweeted_tweet 承载转推的原帖。retweets 是一条帖子被转推的次数,所以自己发的热门帖子 retweets > 0,不代表这条帖子本身是转推。quotes 同样是互动数,不是标记“这一行是引用帖”的字段。目标作者写的引用帖,只要没有 retweeted_tweet 对象,就会留在选中集;own_posts.py 不靠引用次数判断帖子类型。reply_to 是被回复对象的 handle,不是父帖编号。目标作者的回复会保留并标记,选中集不冒充单独的 Replies 栏目。

严格筛选器用什么账号身份?

own_posts.py 支持两条身份路线:

  • ID 路线: 已核实的账号 ID 在 9007199254740991 以内时,用整数 rest_id 请求。
  • handle 路线: ID 超出这个安全数值范围时,请求中只传 screen_name,把事先独立核实的作者 ID 作为字符串保存在本地清单里。不能把大 ID 当整数发送,也不能在 params 里同时放两种身份。

handle 路线避开的是数字请求参数,不能修复以前已经被舍入的请求,也不会自动解析未知的 handle。

handle 路线在 params 之外记录 verified_author_rest_id 和 identity_evidence。identity_evidence 应指向事先核对过的账号记录及核对时间,不能只写“这次响应第一行的作者”。非空的证据描述是来源记录要求,不是自动身份认证;证据含内部账号记录时要私下保管。每一页都必须使用相同的 handle、完整的预期 ID 和同一条证据记录。账号改名或 handle 转移后,重新核实并另起一轮,不要把新旧页合并。

只有 handle、没有已核实 ID 时,使用账号观察指南,不做严格归属。已核查的时间线里,作者姓名和 handle 都为空,所以请求用的 handle 和猜测的 data.user 字段都不能证明每一行的作者。own_posts.py 不解析未知 handle。

保存实际页,再本地筛选

已有响应先复用。新取三页就是三次列表请求,费用按 BeatAPI 价格页计算。每页按实际返回的条目记录。

在原始响应旁建立 own-post-pages.json,把所有占位内容(包括演示账号 ID)换成真实的请求元数据。不要事后根据响应反推当时请求的是哪个账号。

[{"action":"twitter.web.fetch_user_post_tweet","params":{"rest_id":12345},"http_status":200,"collected_at":"2026-11-16T10:00:00Z","response_file":"page-1.json"}]

已事先核实 handle 与账号 ID 的对应关系时,使用下面的清单格式。两个值都是演示用的,不是真实的已核账号;发请求前把两个值都换掉。

[{"action":"twitter.web.fetch_user_post_tweet","params":{"screen_name":"example_handle"},"verified_author_rest_id":"1234567890123456789","identity_evidence":"<verified account record and verification time>","http_status":200,"collected_at":"2026-11-16T10:00:00Z","response_file":"page-1.json"}]

要加入已保存的第二页时,追加一项:账号身份相同,cursor 必须严格等于上一页响应的 data.next_cursor,并记下第二页自己的 request ID 和实际采集时间。own_posts.py 接受 1–20 页,要求从首页开始的同一账号连续链。脚本不补取漏页,不修复重复游标,也不合并不同账号。

把脚本保存为 own_posts.py,执行python3 own_posts.py own-post-pages.json own-post-review:

import csv,hashlib,json,pathlib,re,sys
from datetime import datetime
manifest,target=map(pathlib.Path,sys.argv[1:]);manifest_bytes=manifest.read_bytes();entries=json.loads(manifest_bytes)
if not isinstance(entries,list) or not 1<=len(entries)<=20:raise ValueError('Provide 1..20 saved direct pages')
ACTION='twitter.web.fetch_user_post_tweet';expected_cursor=None;expected_id=None;last_time=None;request_ids=set();used_cursors=set();seen={};rows=[];observations=[];sources=[];raw_files=[]
def ident(v):return isinstance(v,str) and v.isascii() and v.isdigit() and int(v)>0
def cell(v):
text='' if v is None else str(v)
return "'"+text if text.startswith(('=','+','-','@','\t','\r','\n')) else text
for page,e in enumerate(entries,1):
params=e['params']
if not isinstance(params,dict):raise ValueError('Request params must be an object')
if e.get('action')!=ACTION or type(e.get('http_status')) is not int or e['http_status']!=200:raise ValueError('Require successful direct account pages')
if 'screen_name' in params:
handle=params['screen_name'];account=e.get('verified_author_rest_id');evidence=e.get('identity_evidence')
if set(params)-{'screen_name','cursor'} or not isinstance(handle,str) or not re.fullmatch(r'[A-Za-z0-9_]{1,15}',handle):raise ValueError('Use a bare handle only, not a URL or mixed identity')
if not ident(account) or not isinstance(evidence,str) or not evidence.strip():raise ValueError('Provide the previously verified string author ID and its identity evidence')
identity=('screen_name',handle.lower(),account,evidence)
else:
account=params.get('rest_id')
if set(params)-{'rest_id','cursor'} or type(account) is not int or not 0<account<=9007199254740991:raise ValueError('Use a verified safe-range integer rest_id')
account=str(account);identity=('rest_id',account)
if expected_id is None:expected_id=account;expected_identity=identity
if identity!=expected_identity:raise ValueError('Mixed account identity or changed verification evidence')
cursor=params.get('cursor')
if page==1:
if cursor not in (None,''):raise ValueError('Start this bounded run at the first page')
elif not expected_cursor or cursor!=expected_cursor:raise ValueError('Continue with the exact preceding cursor')
if cursor:
if cursor in used_cursors:raise ValueError('Repeated cursor')
used_cursors.add(cursor)
stamp=datetime.fromisoformat(e['collected_at'].replace('Z','+00:00'))
if stamp.utcoffset() is None or last_time is not None and stamp<last_time:raise ValueError('Use chronological timezone-aware observations')
last_time=stamp;path=manifest.parent/e['response_file'];raw=path.read_bytes();response=json.loads(raw)
if response.get('action')!=ACTION or response.get('status')!='succeeded' or response.get('error') is not None:raise ValueError('Unsuccessful or wrong-action response')
rid=response.get('request_id')
if not isinstance(rid,str) or not rid.strip() or rid in request_ids:raise ValueError('Missing or repeated request ID')
request_ids.add(rid);data=response.get('data')
if not isinstance(data,dict) or not isinstance(data.get('timeline'),list):raise ValueError('Expected complete direct data.timeline')
next_cursor=data.get('next_cursor')
if next_cursor is not None and not isinstance(next_cursor,str):raise ValueError('Invalid next cursor')
if next_cursor and (next_cursor==cursor or next_cursor in used_cursors):raise ValueError('Cursor loop')
expected_cursor=next_cursor;archive=f'raw-{page:03}.json';digest=hashlib.sha256(raw).hexdigest();raw_files.append((archive,raw))
sources.append({'file':archive,'sha256':digest,'page':page,'request_id':rid,'params':params,'collected_at':e['collected_at'],'next_cursor':next_cursor,'pinned_present':data.get('pinned') is not None})
for index,post in enumerate(data['timeline']):
if not isinstance(post,dict) or not ident(post.get('tweet_id')):raise ValueError('Original string tweet_id required')
author=post.get('author')
if author is not None and not isinstance(author,dict):raise ValueError('Invalid author')
aid=(author or {}).get('rest_id')
if aid is not None and not ident(aid):raise ValueError('Original string author ID required')
original=post.get('retweeted_tweet')
if original is not None and not isinstance(original,dict):raise ValueError('Unexpected retweeted_tweet type')
for field in ['text','created_at','reply_to']:
if post.get(field) is not None and not isinstance(post[field],str):raise ValueError('Unexpected post text/date/reply field')
classification='repost_object_present' if original is not None else ('author_missing' if aid is None else ('other_author' if aid!=expected_id else 'matching_author_no_repost_object'))
signature=[aid,classification,post.get('text'),post.get('created_at'),post.get('reply_to')]
duplicate=post['tweet_id'] in seen
if duplicate and seen[post['tweet_id']]!=signature:raise ValueError('Conflicting identity/content for repeated post ID')
seen[post['tweet_id']]=signature
row={'tweet_id':post['tweet_id'],'author_rest_id':aid,'target_rest_id':expected_id,'classification':classification,'duplicate_id':duplicate,'page':page,'index':index,'text':post.get('text'),'created_at':post.get('created_at'),'reply_to':post.get('reply_to'),'reply_indicator_present':bool(post.get('reply_to')),'source_file':archive,'source_sha256':digest,'request_id':rid,'collected_at':e['collected_at']}
observations.append(row)
if classification=='matching_author_no_repost_object' and not duplicate:rows.append(row)
target.mkdir()
(target/'input-manifest.json').write_bytes(manifest_bytes)
for name,raw in raw_files:(target/name).write_bytes(raw)
for name,value in [('selected-posts.json',rows),('observations.json',observations),('coverage.json',{'target_rest_id':expected_id,'selected_unique_posts':len(rows),'observations':len(observations),'sources':sources,'manifest_sha256':hashlib.sha256(manifest_bytes).hexdigest(),'next_cursor':expected_cursor,'history_complete':False,'pinned_included':False,'source_identity_independently_authenticated':False,'network_calls':0})]:
(target/name).write_text(json.dumps(value,ensure_ascii=False,indent=2),encoding='utf-8')
fields=['tweet_id','author_rest_id','text','created_at','reply_to','reply_indicator_present','source_file','request_id','collected_at']
with (target/'selected-posts.csv').open('w',encoding='utf-8-sig',newline='') as f:
writer=csv.writer(f);writer.writerow(fields)
for row in rows:writer.writerow([cell(row[k]) for k in fields])
print(json.dumps({'selected_unique_posts':len(rows),'observations':len(observations),'network_calls':0}))

交付什么?

  • selected-posts.csv与JSON:作者原ID匹配请求账号且不带转推对象的去重行,保留正文、原始发布时间、回复标记、来源与采集时间。CSV对公式型文本转义,JSON保持原值。
  • observations.json:所有观察行,包括重复、转推、其他作者和作者缺失。作者没返回不能默认是目标账号。即使 retweeted_tweet 是空对象,也算对象存在,保守排除。
  • raw-NNN.json、原输入清单和coverage.json:原始响应字节、哈希、逐页元数据、真实下一游标与范围。同ID重复只选一次,但观察全留;同ID身份/正文/日期/回复信息冲突则停止。跨页互动数变化不用于修改身份。
  • 置顶对象保留在原响应并记录存在,但不加入选中的时间线,避免重复计算或把未校验的另种结构混入。

例如,一份按输出合同构造的离线样例页包含六行:本作者原帖、本作者引用、本作者回复、一条转推、其他作者、缺失作者。own_posts.py 选出前三行。

own_posts.py 不做时间窗口筛选,也不做互动前三排序。created_at 保留原格式;即使最后一页已存游标为空,也保持 history_complete:false。要“最近两周”或“最好三条”,另行定义时间和指标口径,并在预算内采够页数,不要把首页样本改称全量结果。

交付前核对:所有选中行作者匹配且没有转推对象;每个选中 ID 都能回到原始页;没有覆盖旧输出;本次运行没有产生 API 调用、定时任务或消息。

X问题目录