Yekola ndenge ya kozua na programme mpe ko intégrer ba posts na yo ya Bluesky oyo olingaka na nzela ya authentification, ba appels ya API, na ba points d’arrêt ya oEmbed.
Nauti kosala déplacement likolo ya Bluesky . Nakoki déjà ko confirmer que ezali na communauté tech vibrante kuna na ba tonnes ya contenus intéressants, utile, et inspirants. Nazali mosaleli ya sika ya esengo! Na yango, nazalaki na mposa ya kokɔtisa ba posts na ngai ya Bluesky oyo nalingaka mingi na ba posts na ngai ya sanza na sanza ya zulunalo "Dev roundup". Objectif na ngai ezali ya kopesa liste curée ya ba posts ya Bluesky oyo ezali spécifiquement adapté na ba Développeurs ya Logiciel.
Heureusement, API ya Bluesky ezali entièrement libre ya kosalela, permettant accès programmatique na nionso ya contenus na kati. Mateya oyo ekotambola na yo na nzela ya kozwa mpe kokɔtisa ba posts ya Bluesky oyo olingaka na kosalelaka API na bango, oyo ebongi mpenza mpo na ba blogs personnels, ba portefeuilles, to ba projets ya agrégation ya contenus.
Natongaki script oyo epesi ngai nzela ya ko intégrer automatiquement ba posts na ngai ya Bluesky na poste ya blog ya markdown. Nabanzi ete moko to nyonso ya matambe oyo esalelami na script oyo ezali na motuya mpo na makambo mingi ya kosalela.
Mpo na koloba na mokuse ndenge na ngai ya mosala mpo na kokɔtisa ba posts oyo esepelisi, tolandaka makambo oyo ya ntina:
Tokabola fonction moko na moko na tina na yango:
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; } };
Boyebi ya ntina:
accessJwt
JWT (JSON Web Token) mpo na mabiangi ya API oyo elandicreateSession
uta na ATP ya Bluesky (Protocole ya transfert authentiqué) . 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; };
Boyebi ya ntina:
getActorLikes
mpo na kozwa ba posts oyo esepelisi 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; } };
Boyebi ya ntina:
prettier
mpo na ko formater HTML mbala na mbala<script>
mpo na bokengi mpe botiami ya peto 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); } }
Solution oyo esalaka pona ngai po nionso oyo nasengaka ezali poste ya blog ya sanza na sanza oyo esalemi statique.
Mwa makambo oyo bakoki kobongisa ekoki kozala:
accessJwt
token soki esalelami na ba processus ya longue duréeKo kotisa ba posts ya Bluesky epesaka moyen dynamique ya kolakisa ba interactions na yo na ba médias sociaux. Na kososolaka mosala ya API mpe kosalelaka bokambami ya mabunga ya makasi, okoki kosala bosangisi ya makambo oyo ekobenda likebi, oyo ebongisami mpo na moto ye moko, mpe oyo ebongisami.
Sepela mpe esengo tinkering! 🚀