paint-brush
Bluesky ukan API Gratis ukax Nayan Jach’a Posts ukanakar Curar ukham yanapt’itu, kunjamatix Janipuniw Nayrjax ukhamaukata@noahm
Machaq sarnaqäwi

Bluesky ukan API Gratis ukax Nayan Jach’a Posts ukanakar Curar ukham yanapt’itu, kunjamatix Janipuniw Nayrjax ukhama

ukata Noah5m2024/12/17
Read on Terminal Reader

Sinti jaya pachanakawa; Uñxatt’añataki

Yatxatapxañani kunjamasa programaticamente apsuña ukatxa uñt’ayaña munata Bluesky qillqatanakaxa chiqapa uñt’ayawi, API jawsatanaka, ukhamaraki oEmbed tukuyañanakampi.
featured image - Bluesky ukan API Gratis ukax Nayan Jach’a Posts ukanakar Curar ukham yanapt’itu, kunjamatix Janipuniw Nayrjax ukhama
Noah HackerNoon profile picture

Yatxatapxañani kunjamasa programaticamente apsuña ukhamaraki uñt’ayaña munata Bluesky qillqatanakaxa chiqapa uñt’ayawi, API jawsatanaka, ukhamaraki oEmbed tukuyañanakampi.


Jichhakiw Bluesky ukar sarxawayta. Nayax nayratpach chiqanchañjamawa, ukanx mä ch’amanchata comunidad tecnológica ukaw utji, toneladas de contenidos interesantes, útiles ukat inspiradores ukanakampi. ¡Nayax mä kusisit machaq apnaqiritwa! Ukhamatwa, Bluesky ukan wali munat qillqatanakax "Dev roundup" phaxsi yatiyäw qillqatanakanx uñt'ayañ munta. Nayan amtäwijasti mä lista curada Bluesky ukan qillqatanakap uñt’ayañawa, ukax Software Developers ukar uñt’ayatawa.


Suertenixa, Bluesky ukan API ukax taqpach apnaqañapatakix inakiw, ukax programatico ukar mantañapatakiw taqi kunatix ukan utjki ukanakar mantañapataki. Aka yatichäwix Bluesky ukan munat qillqatanakap API apnaqañamp apsuñ ukhamarak uñt’ayañ thakhinjam irpapxätam, blogs personales, carteras jan ukax proyectos de agregación de contenidos ukanakatakix wali askiwa.

Nayan Bluesky API Workflow ukar amuyaña

Nayax mä script lurawayta, ukax Bluesky ukan qillqatanakax mä markdown blog post ukar automáticamente uñt’ayañatakiw yanapt’itu. Nayax amuyta, kawkir jan ukax taqpach lurawinakas aka script ukan apnaqatäki ukax walja apnaqañ-caso ukanakatakix wali askiwa.


Nayan lurawix mä juk’a qhanañcht’añatakix gustat posts ukanakar uñt’ayañatakix aka jach’a lurawinakampiw arktasipxta:

  1. Mä chiqapa sesión luraña
  2. Mä "actor" ukatak URIs post liked ukanak apsuña.
  3. Aka URIs ukanakax oEmbed embed HTML ukar apsuñatakiw apnaqasi
  4. Q’umachaña ukat formato ukax código embed ukaruw uñt’ayasi


Uka Phuqata phuqhawi

Sapa lurawi ukhamaraki kuna amtampis lurasi ukxat t’aqanuqt’añäni:

1. Bluesky Sesión luraña

 export const createSession = async (): Promise<string | null> => { try { const response = await fetch( "https://bsky.social/xrpc/com.atproto.server.createSession", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ identifier: "your-handle", password: "your-password", }), } ); const responseJson = await response.json(); return responseJson.accessJwt; } catch (e) { console.error("Failed to create session: ", e); return null; } };


Jach’a amuyunaka:

  • Aka lurawix Bluesky ukan cuentap chiqanchatawa.
    • Qhanacht’awi: aka uñacht’awix credenciales ukanakatakix cadenas ukanakaruw hardcodes uñacht’ayi, ukampis ukax producción apnaqañanx jan lurañaw wakisi.
  • Ukax mä accessJwt JWT (JSON Web Token) ukaruw kutt’ayaraki, qhipa API jawsatanakataki
  • Bluesky ukan ATP (Protocolo de Transferencia Autenticado) ukan createSession tukuyañ chimpu apnaqi .
  • Pantjasiw apnaqañax gracioso jan walt’awinak askichi, chiqanchawix jan walt’ayaspa ukhaxa

2. Liked Post URIs ukanaka apsuña

 export const getBlueskyLikeUris = async (actor: string, limit: number = 40) => { const token = await createSession(); if (!token) { console.error("Failed to get token"); return; } const response = await fetch( "https://bsky.social/xrpc/app.bsky.feed.getActorLikes?actor=${actor}&limit=${limit}", { method: "GET", headers: { Authorization: `Bearer ${token}`, }, } ); const responseJson = await response.json(); const uris = responseJson.feed.map((entry: any) => entry.post.uri); return uris; };


Jach’a amuyunaka:

  • Mä chiqapa sesión token ukax wakisiwa
  • getActorLikes tukuyañ chimpumpiw uñt’ayasi getActorLikes ukax wali askiwa
  • Wali askiw -- dominio de punto final ukax https://bsky.social ukhamäñapawa, kunatix akax mä chiqapa mayiwiwa.
  • Sapa munat qillqatanakatakix sapa mayni URIs ukanakaw apsu
  • Límites ukax 40 posts (configurable) ukhamawa.

3. URIs ukanakax HTML Embeddable ukar jaqukipaña

 export const getBlueskyPostEmbedMarkup = async (uri: string) => { try { const response = await fetch(`https://embed.bsky.app/oembed?url=${uri}`); const responseJson = await response.json(); const formattedHTML = prettier.format(responseJson.html, { parser: "html", plugins: [require("prettier/parser-html")], htmlWhitespaceSensitivity: "ignore", printWidth: 1000, }); return formattedHTML.replace(/<script[\s\S]*?<\/script>/g, ""); } catch (e) { console.error("Failed to get Bluesky post embed markup"); return null; } };


Jach’a amuyunaka:

  • Bluesky ukax oEmbed tukuyañ chimpumpiw post URIs ukampiw apnaqasi, mä post ukan HTML ukar mantañataki
  • Opcional: Usuario prettier ukax HTML ukax formato constante ukhamawa
  • Munañjama: <script> chimpunak apsuña seguridad ukat q’uma uñt’ayañataki
    • Ukax kunatsa ukhamaxa, sapa post ukax Bluesky ukan contenido ukan utjki ukatakix mä sapa Bluesky script ukaw uñt’ayasi.
  • Flexible pantjasiwinak apnaqaña

Taqi ukanak mayacht’aña: Mä phuqhat uñacht’äwi

 async function embedLikedPosts() { try { // Get liked post URIs const likedPostUris = await getBlueskyLikeUris(); if (!likedPostUris) { console.error("No liked posts found"); return; } // Convert URIs to embed HTML const embedPromises = likedPostUris.map(getBlueskyPostEmbedMarkup); const embedHtmlArray = await Promise.all(embedPromises); // Filter out any failed embeds const validEmbeds = embedHtmlArray.filter(embed => embed !== null); // Return the markup for all liked posts return ` ## Some Fave Posts 🦋 ${validEmbeds.join(`\n\n`)} ` } catch (error) { console.error("Error embedding Bluesky posts:", error); } }

Ukax mä jach’a ch’amanchawiwa

Aka solución ukax nayatakix irnaqaskiw kunatix taqi kunatix nayatakix wakiski ukax mä post blog ukan sapa phaxsi estáticamente generado ukawa.


Mä qhawqha askinak lurañax akanakawa:

  • 40 jila uñt’at qillqatanakar apsuñatakix paginación ukan yanapt’äwip yapxatañamawa
  • Caché ukar phuqhaña, jan wakiskir API jawsatanakar jisk’achañataki
  • Mä juk’amp ch’aman pantjasiwinak apnaqañ mecanismo luraña
  • Mecanismo luraña accessJwt token ukar machaqar tukuyañataki, ukax jaya pachan lurawinakan apnaqatawa
  • Uñt’at qillqatanakax wali uñt’atawa (like) ukarjam uñt’ayaña .

Jan walt’awinak askichañataki iwxt’awinaka

  • Bluesky ukan credenciales ukanakax chiqapätap uñakipt’añamawa
  • Uñakipt’añani Bearer token ukaxa chiqapa mayiwinakanxa utt’ayatawa.
  • Uñakipt’aña, kuna dominios de puntos finales ukanakas apnaqañax taqpachaw wakisi.

Tukuyawi

Bluesky ukan qillqatanakap uñt’ayañax mä ch’amanchawiw medios sociales ukan mayacht’asiwinakap uñacht’ayañataki. API irnaqawi amuyt’asa ukhamaraki ch’amani pantjasiwi apnaqawi phuqhasa, ukaxa lurasispawa, ukaxa lurasispawa, ukaxa mä juk’a pachanakwa lurasirakispa.

Jutïr lurañanaka

  1. Uka codigompi yant’aña
  2. Uka embed estilo ukarux uñt’ayañamawa
  3. Yaqha Bluesky API tukuyañ chiqanakat yatxatañamawa


¡Kusisiña ukat kusisita tinkering! 🚀