resolve returns media for one Facebook post, photo or video.
listFacebookPosts returns a page of a page’s or profile’s public posts. Both
read the public web pages and send no cookies.
Resolve a post
resolve fetches the page at the URL and reads the post it shows. It accepts
facebook.com, m.facebook.com, web.facebook.com, fb.com and fb.watch
URLs. The tests cover these forms:
- A post:
/<page>/posts/<id> - A photo:
/photo/?fbid=<id> - A video:
/watch/?v=<id>
import { resolve } from "@totallynotdavid/downloader";
const result = await resolve(
"https://www.facebook.com/1551UNMSM/posts/1582271390604244",
);
A post with several photos is a carousel with one item per photo. The post page embeds only the first few; the rest come from the post’s media set page and one page per photo, so a 10-photo post costs about 7 requests.
A share link (/share/p/…, /share/v/…) answers with a login page and rejects
with a NetworkError of status 401. Open the link in a browser and pass the
address it lands on. A deleted or private post rejects with status 404.
List an account’s posts
import { listFacebookPosts } from "@totallynotdavid/downloader";
const first = await listFacebookPosts("1551UNMSM");
for (const post of first.posts) {
console.log(post.type, post.url, post.caption);
}
if (first.cursor) {
const next = await listFacebookPosts("1551UNMSM", { cursor: first.cursor });
}
listFacebookPosts(account, options?) returns posts newest first in the Post
and PostPage shapes described in
Instagram. The account is one of:
- a page name such as
1551UNMSM, or a numeric profile ID - a profile URL:
https://www.facebook.com/1551UNMSM, a tab such as/1551UNMSM/videos,/profile.php?id=<id>, or/people/<name>/<id>
Each Post.url is an address resolve accepts. A carousel links to its post, a
photo to /photo/?fbid=, and a video to /watch/?v=. Post.shortcode is the
post ID.
A page holds up to 12 posts. The timeline returns 3 stories per request, so a
page costs up to 4 requests, plus one for the profile on the first page. Stories
without a photo or video of their own, such as shares and text posts, are left
out, so a page can hold fewer than 12. The cursor has the form
<user id>:<timeline cursor>; pass it back unchanged.
Errors
| Case | Error |
|---|---|
| A malformed account or cursor | ParseError, before any request |
| An account shown only to signed-in users | NetworkError with status 401 |
| An unknown account | NetworkError with status 404 |
| A timeline error or unexpected reply | ParseError |