get-likes.js
1// let's count the number of likes on a Bluesky post
2// ...but without using any Bluesky infrastructure at all!
3
4// Constellation knows about *all* references to every record
5// This API counts up the unique identities from those references
6const url = new URL('https://constellation.microcosm.blue/links/count/distinct-dids')
7
8// set the bluesky post's record at-uri as the "target"
9const record_uri = 'at://did:plc:hdhoaan3xa3jiuq4fg4mefid/app.bsky.feed.post/3lwcmto4tck2h';
10url.searchParams.set('target', record_uri);
11
12// filter references to those from bluesky likes
13url.searchParams.set('collection', 'app.bsky.feed.like')
14url.searchParams.set('path', '.subject.uri')
15
16// let's go!
17const res = await fetch(url);
18const { total } = await res.json();
19// total now has the count of likes on our post!