最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - Getting posts from a Bluesky feed, in Node.js, using the @atprotoapi package? - Stack Overflow

programmeradmin1浏览0评论

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).

Share asked Mar 6 at 19:41 Andre MAndre M 7,5989 gold badges64 silver badges107 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

While 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论