Перейти к навигации

Does null views mean zero views?

No. In a saved twitter.web.fetch_search_timeline response, null in data.timeline[].views means that observation returned no view value; only the string "0" represents a reported zero. Exclude null and absent views entries from averages, and state how many posts reported a view value alongside every average.

Check whether a post reports a view count

Inspect data.timeline[].views on each post. The published type of views is string or null:

views valueMeaningIn an average
"0"Reported zeroInclude
nullNo value returned in this observationExclude
No views keyAbsent; record the post separately as absentExclude

The views field alone does not establish that a post was deleted, private, newly published, or never viewed.

How does missing coverage change a research report?

Take three sample posts with views values of "100", "0", and null. Report 2 of 3 with available views, an observed sum of 100, and a mean of 100 / 2 = 50 across the two posts with reported values. Dividing by all three posts treats null as zero, distorts the average, and conceals missing metric coverage. A mean of 50 applies only to those two reported posts—not the full audience, not unique reach, and not an estimate for all matching posts on X.

When comparing two keyword sets, show view availability next to each mean. A set where few posts report views cannot be compared directly with a set where nearly all posts report views. Save each query, sort mode, and observation time alongside the source response file. Across repeated snapshots, match by tweet_id and compute a delta only when both snapshots report a numeric string value; leave other deltas blank.

Make a coverage table from one saved search page

Start from a saved successful response collected via the keyword-search guide. views_coverage.py makes no calls to X or BeatAPI, fetches no extra pages, and invokes no model. Keep the original request manifest beside the output folder so reviewers can audit the query and sort settings. When the response includes a continuation cursor, views_coverage.py records continuation_available without following the cursor.

Save the script as views_coverage.py:

import csv,datetime,hashlib,json,pathlib,sys
source=pathlib.Path(sys.argv[1]);stamp=sys.argv[2];target=pathlib.Path(sys.argv[3])
dt=datetime.datetime.fromisoformat(stamp.replace("Z","+00:00"))
if dt.tzinfo is None:raise ValueError("Record the actual collection time with timezone")
raw=source.read_bytes();payload=json.loads(raw);action="twitter.web.fetch_search_timeline"
if not isinstance(payload,dict) or payload.get("status")!="succeeded" or payload.get("action")!=action or payload.get("error") is not None:raise ValueError("Use a successful search response")
rid=payload.get("request_id")
if not isinstance(rid,str) or not rid.strip():raise ValueError("Missing request ID")
data=payload.get("data")
if not isinstance(data,dict) or not isinstance(data.get("timeline"),list):raise ValueError("Missing timeline array is not an empty page")
cursor=data.get("next_cursor")
if cursor is not None and not isinstance(cursor,str):raise ValueError("Unexpected cursor type")
rows=[];seen=set();total=0;counts={"reported":0,"null":0,"absent":0}
for item in data["timeline"]:
if not isinstance(item,dict):raise ValueError("Invalid post object")
ident=item.get("tweet_id")
if not isinstance(ident,str) or not ident.isascii() or not ident.isdigit() or int(ident)==0 or ident in seen:raise ValueError("Require distinct original nonzero string IDs")
seen.add(ident)
state="absent" if "views" not in item else ("null" if item["views"] is None else "reported")
value=None
if state=="reported":
text=item["views"]
if not isinstance(text,str) or not text.isascii() or not text.isdigit():raise ValueError("views must be its original digit string, null or absent")
value=int(text);total+=value
counts[state]+=1
rows.append({"tweet_id":ident,"views_state":state,"views":"" if value is None else str(value)})
digest=hashlib.sha256(raw).hexdigest()
summary={"action":action,"request_id":rid,"collected_at":stamp,"source_sha256":digest,
"unique_posts":len(rows),"states":counts,"reported_sum":str(total),
"reported_mean_fraction":None if not counts["reported"] else {"numerator":str(total),"denominator":counts["reported"]},
"coverage_fraction":{"numerator":counts["reported"],"denominator":len(rows)} if rows else None,
"scope":"one saved search page","continuation_available":bool(cursor and cursor.strip())}
target.mkdir()
(target/"raw-response.json").write_bytes(raw)
(target/"summary.json").write_text(json.dumps(summary,ensure_ascii=False,indent=2),encoding="utf-8")
with (target/"views.csv").open("x",encoding="utf-8-sig",newline="") as f:
writer=csv.DictWriter(f,fieldnames=["tweet_id","views_state","views"]);writer.writeheader();writer.writerows(rows)
print(str(target))

Run python3 views_coverage.py page-1.json ACTUAL_COLLECTION_TIME new-coverage-folder. Replace ACTUAL_COLLECTION_TIME with the timezone-aware timestamp recorded when the response was collected (for example 2026-11-16T10:00:00Z), using the real collection timestamp rather than the example value. The destination folder new-coverage-folder must not exist yet.

The output folder contains views.csv, summary.json, and a byte-identical copy of the input as raw-response.json. summary.json stores every ratio as an exact integer numerator and denominator so large counts avoid floating-point rounding. A page with zero reported values has no mean, and a successful empty page has no coverage fraction; an empty page and a page where every views value is null are distinct states. views_coverage.py exits before creating output on duplicate IDs, malformed values, failed calls, or missing timeline arrays. If views_coverage.py rejects an unexpected numeric value, inspect the original response instead of converting the value to a string by guesswork.

source_sha256 in summary.json fingerprints the saved response bytes without proving authenticity or verifying the manually entered timestamp. Import numeric-looking tweet_id values and large counts into spreadsheets as plain text to preserve precision. Re-running views_coverage.py consumes no API calls; refreshing data or following a cursor requires a new request.

Search-page CSV and original request manifest · Diagnose an empty search result

Contract reference: data:twitter.web.fetch_search_timeline.