Something

async function getMediumPosts() {
try {
const response = await fetch(‘https://api.medium.com/v1/users/@sukhrobtech/posts’, {
headers: {
Authorization: `Bearer 29a6e098e7413bb577279281bb650edd904329dfc1561bfc6…


This content originally appeared on DEV Community and was authored by Sukhrob Tech

Image description

async function getMediumPosts() {
    try {
        const response = await fetch('https://api.medium.com/v1/users/@sukhrobtech/posts', {
            headers: {
                Authorization: `Bearer 29a6e098e7413bb577279281bb650edd904329dfc1561bfc687600f4ca656609b`,
            },
        });

        if (!response.ok) {
            throw new Error(`Error: ${response.status} ${response.statusText}`);
        }

        const data = await response.json();
        return data.data; // Assuming that posts are in the `data` field of the response
    } catch (error) {
        console.error("Failed to fetch Medium posts:", error);
        return []; // Return an empty array if there's an error
    }
}

const Page = async () => {
    const posts = await getMediumPosts();

    return (
        <div>
            <h2>My Medium Articles</h2>
            <ul>
                {posts.length > 0 ? (
                    posts.map((post) => (
                        <li key={post.id}>
                            <a href={post.url} target="_blank" rel="noopener noreferrer">
                                {post.title}
                            </a>
                        </li>
                    ))
                ) : (
                    <li>No articles found.</li>
                )}
            </ul>
        </div>
    );
};

export default Page;


This content originally appeared on DEV Community and was authored by Sukhrob Tech


Print Share Comment Cite Upload Translate Updates
APA

Sukhrob Tech | Sciencx (2024-10-26T03:47:21+00:00) Something. Retrieved from https://www.scien.cx/2024/10/26/something/

MLA
" » Something." Sukhrob Tech | Sciencx - Saturday October 26, 2024, https://www.scien.cx/2024/10/26/something/
HARVARD
Sukhrob Tech | Sciencx Saturday October 26, 2024 » Something., viewed ,<https://www.scien.cx/2024/10/26/something/>
VANCOUVER
Sukhrob Tech | Sciencx - » Something. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/26/something/
CHICAGO
" » Something." Sukhrob Tech | Sciencx - Accessed . https://www.scien.cx/2024/10/26/something/
IEEE
" » Something." Sukhrob Tech | Sciencx [Online]. Available: https://www.scien.cx/2024/10/26/something/. [Accessed: ]
rf:citation
» Something | Sukhrob Tech | Sciencx | https://www.scien.cx/2024/10/26/something/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.