Knowing who engages with your Medium articles can provide valuable insights into your audience. By fetching the fans (users who clapped for an article), you can understand your readers better and even tailor your content to align with their preferences.
Here’s a straightforward way to achieve this using the medium-api-js
package. By the end of this guide, you’ll know how to retrieve the list of fans for any Medium article.
To set up and execute the code:
dotenv
package to store sensitive data like your API key securely.npm install medium-api-js dotenv
Below is a breakdown of the code used to fetch the fans of a Medium article.
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
dotenv.config();
Medium
: This is the main class from the medium-api-js
package that allows interaction with Medium’s API.dotenv
: Enables the use of environment variables stored in a .env
file.dotenv.config()
: Loads the environment variables from the .env
file into the application.const medium = new Medium(process.env.RAPIDAPI_KEY);
process.env.RAPIDAPI_KEY
: Fetches the API key securely from the .env
file.Medium()
: Initializes the Medium API client with the provided API key.const articleId = '67fa62fc1971';
articleId
: A unique identifier for the Medium article whose fans you want to retrieve.medium.getArticleFans(articleId).then(data => {
console.log('Article Fans:', data); // Output the fans of the article
});
getArticleFans(articleId)
: A method provided by the medium-api-js
package to fetch fans of the specified article..then(data => { ... })
: Handles the promise returned by the method and logs the response containing the article’s fans.Save the code in a file, e.g., getArticleFans.js
, and run the following command in the terminal:
node getArticleFans.js
Ensure that the .env
file is properly configured with your API key:
RAPIDAPI_KEY=your_rapidapi_key_here
When the code executes successfully, the output will display the details of the article’s fans:
id
: The ID of the article whose fans were fetched.voters
: An array of user IDs representing the fans who clapped for the article.count
: The total number of fans.In the sample output, the article has 143 fans, with the voters
array listing their IDs.
Fetching fans of a Medium article is an excellent way to gain insights into your readership and engagement levels. By using the medium-api-js
package, this process is simplified and efficient. Implement this code to unlock deeper connections with your audience.
For any questions or clarifications, feel free to reach out at nishu@mediumapi.com.