admin管理员组文章数量:1405855
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.
本文标签:
版权声明:本文标题:typescript - Getting posts from a Bluesky feed, in Node.js, using the @atprotoapi package? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744953165a2634201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论