How to Get Medium User Information

(Using Javascript)

Fetching detailed information about a Medium user can be a valuable tool for developers, content creators, and marketers looking to analyze profiles, build personalized experiences, or manage interactions.

This guide explains how to retrieve Medium user information using the "medium-api-js" package by providing the user's ID. The outcome is a comprehensive user profile containing key details like name, bio, follower counts, and more.

Prerequisites

To successfully implement this, ensure the following are in place:

Run the following commands to install the dependencies:

npm install medium-api-js dotenv

Code Explanation

Here’s a step-by-step breakdown of the script to fetch Medium user information:

1. Import Required Libraries

import Medium from 'medium-api-js';
import dotenv from 'dotenv';

The medium-api-js package provides methods to interact with the Medium API, while dotenv allows you to load sensitive credentials securely from a .env file.

2. Configure Environment Variables

dotenv.config();

This line ensures the environment variables, including your API key, are loaded from the .env file.

3. Initialize the Medium Client

const medium = new Medium(process.env.RAPIDAPI_KEY);

The Medium client is initialized with your RapidAPI key, enabling authenticated requests to the Medium API.

4. Fetch User Information

medium.getUserInfo('1985b61817c3')
    .then(data => console.log('User Info:', data));

The getUserInfo method takes a user ID (e.g., 1985b61817c3) and returns a promise. Upon resolution, it logs the user’s details to the console.

Command to Run the Script

Save the script as getUserInfo.js and execute it with the following command:

node getUserInfo.js

Output Explanation

When the script runs successfully, the output will display detailed user information in JSON format:

Key Details:

Potential Use Cases

Summary

Retrieving Medium user information is straightforward and opens doors to many practical applications in analytics, content creation, and user engagement. With the Medium API and medium-api-js, you can easily fetch, analyze, and utilize profile data for various purposes.

For further assistance or queries regarding the Medium API, feel free to reach out at nishu@mediumapi.com.

nishu@mediumapi.com