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.
To successfully implement this, ensure the following are in place:
RAPIDAPI_KEY
by signing up for the Medium API service on RapidAPI..env
file to securely store your API key.dotenv
: for environment variable management.medium-api-js
: a wrapper for Medium API.Run the following commands to install the dependencies:
npm install medium-api-js dotenv
Here’s a step-by-step breakdown of the script to fetch Medium user information:
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.
dotenv.config();
This line ensures the environment variables, including your API key, are loaded from the .env
file.
const medium = new Medium(process.env.RAPIDAPI_KEY);
The Medium client is initialized with your RapidAPI key, enabling authenticated requests to the Medium API.
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.
Save the script as getUserInfo.js
and execute it with the following command:
node getUserInfo.js
When the script runs successfully, the output will display detailed user information in JSON format:
Key Details:
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.