1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Deno DeployでBlueskyにツイートするAPI【ポスト】

Last updated at Posted at 2024-02-29
curl https://b-sky.deno.dev?identifier=laravel11.bsky.social&password=PASSWORD&text=やあ

laravel11.bsky.socialPASSWORDは適宜書き換えてね!
https://bsky.app/profile/laravel11.bsky.social

See the Pen Bluesky Post by John Doe (@04) on CodePen.

ソースコード

import AtprotoAPI from 'npm:@atproto/api'

Deno.serve(async (req: Request) => {
    const headers = { 'Access-Control-Allow-Origin': '*' }
    const { identifier, password, text = 'こんにちは!', service = 'https://bsky.social' } = Object.fromEntries(new URL(req.url).searchParams)
    try {
        const agent = new AtprotoAPI.BskyAgent({ service })
        await agent.login({ identifier, password })
        const richText = new AtprotoAPI.RichText({ text })
        await richText.detectFacets(agent)
        const response = await agent.post({
            $type: 'app.bsky.feed.post',
            text: richText.text,
            facets: richText.facets,
        })
        return Response.json(response, { headers })
    } catch (e) {
        return new Response(e.message, { status: 400, headers })
    }
});
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?