I am wanting to list the posts for any given Bluesky account, using the @atproto/api (0.14.7) package in Node.js, but I am running into issues when using getPosts()
.
I am not sure as to what the right URI should be, and I am having a hard time finding any examples of how to use the function call correctly. I have tried a range, but run into failures.
import { AtpAgent, AtpSessionEvent, AtpSessionData } from '@atproto/api'
const identifier = 'myuser.bsky.social';
const password = 'xxxx-xxxx-xxxx';
const bSkyService = '';
async function main () {
const agent = new AtpAgent({
service: bSkyService,
persistSession: (evt: AtpSessionEvent, sess?: AtpSessionData) => {
// store the session-data for reuse
},
});
await agent.login({
identifier,
password,
});
const feedUri = `at://${agent.assertDid}/app.bsky.feed.generator`;
const response = await agent.getPosts({ uris: [feedUri] });
console.log('Response:', response);
}
main().catch(error => {
console.log(error);
process.exit(1);
})
Errors based on values for URIs I am using:
- 'at://myuser.bsky.social' : 'XRPCError: Internal Server Error'
at://${agent.assertDid}/app.bsky.feed.generator
: 'XRPCError: Internal Server Error'- 'myuser.bsky.social' : 'XRPCError: Error: uris/0 must be a valid at-uri'
agent.assertDid
: 'RPCError: Error: uris/0 must be a valid at-uri'- 'at://bsky.social/myuser.bsky.social' : 'XRPCError: Internal Server Error'
Can anyone indicate what I should be doing or whether there is an alternative way to list posts from a user's feed?
Note: I have also tried without login, but that results in the same issue for all attempts (except for agent.assertDid
which does require a login).
I am wanting to list the posts for any given Bluesky account, using the @atproto/api (0.14.7) package in Node.js, but I am running into issues when using getPosts()
.
I am not sure as to what the right URI should be, and I am having a hard time finding any examples of how to use the function call correctly. I have tried a range, but run into failures.
import { AtpAgent, AtpSessionEvent, AtpSessionData } from '@atproto/api'
const identifier = 'myuser.bsky.social';
const password = 'xxxx-xxxx-xxxx';
const bSkyService = 'https://bsky.social';
async function main () {
const agent = new AtpAgent({
service: bSkyService,
persistSession: (evt: AtpSessionEvent, sess?: AtpSessionData) => {
// store the session-data for reuse
},
});
await agent.login({
identifier,
password,
});
const feedUri = `at://${agent.assertDid}/app.bsky.feed.generator`;
const response = await agent.getPosts({ uris: [feedUri] });
console.log('Response:', response);
}
main().catch(error => {
console.log(error);
process.exit(1);
})
Errors based on values for URIs I am using:
- 'at://myuser.bsky.social' : 'XRPCError: Internal Server Error'
at://${agent.assertDid}/app.bsky.feed.generator
: 'XRPCError: Internal Server Error'- 'myuser.bsky.social' : 'XRPCError: Error: uris/0 must be a valid at-uri'
agent.assertDid
: 'RPCError: Error: uris/0 must be a valid at-uri'- 'at://bsky.social/myuser.bsky.social' : 'XRPCError: Internal Server Error'
Can anyone indicate what I should be doing or whether there is an alternative way to list posts from a user's feed?
Note: I have also tried https://public.api.bsky.app without login, but that results in the same issue for all attempts (except for agent.assertDid
which does require a login).
1 Answer
Reset to default 0While I didn't get any answers around getPosts()
, it turns out that getAuthorFeed()
functions for my needs.
To list only the posts the account has created (as opposed to replies to other posts):
const response = await agent.getAuthorFeed({
actor: 'myuser.bsky.social',
includePins: false,
filter: 'posts_no_replies'
});
You can also use the following, if logged in and wanting to return your own feed:
const response = await agent.getAuthorFeed({
actor: agent.assertDid,
includePins: false,
filter: 'posts_no_replies'
});
This is all based on the code in the question.