Baro sida barnaamij ahaan loogu soo saaro oo u dhexgeliyo qoraaladaada Bluesky ee aad jeceshahay adiga oo isticmaalaya xaqiijin, wicitaanada API, iyo oEmbed dhamaadka.
Waxaan dhawaan u wareegay Bluesky . Waxaan horeyba u xaqiijin karaa inay jirto bulsho tignoolajiyadeed firfircoon oo halkaas ka kooban waxyaabo xiiso leh, faa'iido leh, iyo dhiirigelin leh. Waxaan ahay isticmaale cusub oo faraxsan! Natiijo ahaan, waxaan doonayay inaan ku dhejiyo fariimahayga ugu sarreeya ee Bluesky-ga ee aan jeclahay qoraalladayda warsidaha billaha ah ee "Dev roundup". Ujeedadaydu waa in aan bixiyo liis la soo koobay oo ah qoraalada Bluesky kuwaas oo si gaar ah loogu talagalay Soosaarayaasha Software-ka.
Nasiib wanaag, Bluesky's API gabi ahaanba waa xor in la isticmaalo, taas oo u oggolaanaysa gelitaanka barnaamijka dhammaan waxyaabaha ku jira. Casharradani waxay ku socon doontaa habka aad dib ugu soo celin lahayd oo aad ugu dhejin lahayd qoraallada Bluesky ee la jecel yahay iyaga oo isticmaalaya API-gooda, oo ku habboon blogyada gaarka ah, faylalka, ama mashaariicda isku-darka nuxurka.
Waxaan dhisay qoraal ii ogolaanaya inaan si toos ah ugu dhejiyo qoraaladeyda Bluesky boostada blog-ka calaamadaynta. Waxaan u maleynayaa in mid ama dhammaan tillaabooyinka lagu isticmaalo qoraalkan ay qiimo u leeyihiin kiisas badan oo la isticmaalo.
Si aan u soo koobo socodka shaqadayda ee ku dhejinta qoraalada la jecel yahay, waxaanu raacnaa talaabooyinkan muhiimka ah:
Aynu kala saarno hawl kasta iyo ujeeddadeeda:
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; } };
Aragtida Muhiimka ah:
accessJwt
JWT (JSON Web Token) wicida xiga ee APIcreateSession
barta dhamaadka kulanka Bluesky's ATP (Borotokoolka Wareejinta La Xaqiijiyay 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; };
Aragtida Muhiimka ah:
getActorLikes
si uu u soo saaro qoraallada la jecel yahay 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; } };
Aragtida Muhiimka ah:
prettier
inuu u habeeyo HTML-ka si joogto ah<script>
sumadaha amniga iyo ku-xidhka nadiifka ah 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); } }
Xalkani wuu ii shaqeeyaa sababtoo ah waxa kaliya ee aan u baahanahay waa boostada blog-ka ee bilaha ah.
Horumarrada qaarkood waxaa ka mid noqon kara:
accessJwt
token haddii loo isticmaalo geeddi-socodyada dheer ee socdaKu dhejinta qoraallada Bluesky waxay ku siinaysaa hab firfircoon oo lagu muujiyo isdhexgalkaaga warbaahinta bulshada. Markaad fahamto socodka shaqada API iyo hirgelinta khaladka adag ee maaraynta, waxaad abuuri kartaa ka-qaybgal, la gaaryeelay, iyo isku-dhafka nuxurka.
Ku raaxayso oo tinkering faraxsan! 🚀