How to Get Tags in Which a User is Interested

(Using Medium API with Javascript)

Medium has become a platform for millions of readers and writers, where personalization and relevant content play a pivotal role in keeping users engaged.

Suppose you want to analyze or tailor content based on user interests. In that case, you can fetch the tags they follow using their Medium user ID, enabling you to deliver curated experiences. Here's a step-by-step guide to achieve this using the "medium-api-js" package.

By the end of this guide, you'll know how to fetch the list of tags a Medium user is interested in and understand how to interpret the data.

Prerequisites

Before diving into the code, ensure you have the following:

Code Explanation

The following code fetches the tags a user is interested in:

1. Importing Dependencies

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

dotenv.config();

2. Initializing the Medium API

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

Creates an instance of the Medium API client using your API key stored in the .env file.

3. Defining the User ID

const userId = '1985b61817c3';

Replace '1985b61817c3' with the actual user ID whose interests you want to retrieve.

4. Fetching User Interests

medium.getUserInterests(userId)
    .then(data => console.log('User Interests:', data));

Running the Code

Save the code in a file named getUserInterests.js and run the following command in your terminal:

node getUserInterests.js

Output

The script outputs a JSON object to the console. Here’s a sample output:

Explanation of the Output

Potential Use Cases

Summary

Fetching user interests using their Medium user ID is straightforward with the medium-api-js package. This process can unlock a plethora of opportunities, from improving user experiences to driving better engagement through tailored content and insights.

If you have any questions or need further assistance, feel free to reach out to nishu@mediumapi.com.

Happy coding!

nishu@mediumapi.com