Searching for specific users on Medium can be highly useful for discovering influential writers, finding collaborators, or simply connecting with like-minded individuals.
This guide explains how to use the medium-api-js
package to perform a search for users on Medium using a simple JavaScript script. The script demonstrates how to fetch user IDs associated with a search query.
Before you begin, ensure the following prerequisites are met:
medium-api-js
Package: Install the package using npm:npm install medium-api-js dotenv
.env
file and include your API key:RAPIDAPI_KEY=your_api_key_here
import Medium from 'medium-api-js';
import dotenv from 'dotenv';
dotenv.config();
Medium
: Provides an interface for interacting with Medium's API.dotenv
: Loads environment variables from a .env
file.dotenv.config()
: Ensures environment variables are accessible in the script.const medium = new Medium(process.env.RAPIDAPI_KEY);
process.env.RAPIDAPI_KEY
: Retrieves the API key from the environment variables.Medium Constructor
: Initializes the client with the API key.medium.getSearchUsers('John Doe').then(data => {
console.log('Search Results for Users:', data);
});
medium.getSearchUsers('John Doe')
: Searches for users matching the query 'John Doe'
..then(data => { ... })
: Handles the resolved promise with the search results.console.log
: Logs the search results to the console.Execute the script using the following command:
node getSearchUsers.js
Ensure the file is saved as getSearchUsers.js
or modify the command to match the filename.
When the script runs successfully, it fetches and logs the search results for users matching the query 'John Doe'
. The output will look similar to this:
users
: An array of user IDs matching the query.search_query
: The search string used in the request.With this script, you can effortlessly search for Medium users by name or keyword, making it a valuable tool for creators, researchers, and developers.
By leveraging the medium-api-js
package, integrating Medium's API into your applications becomes straightforward and efficient.
For questions or further assistance, contact nishu@mediumapi.com.