Medium

免费增值
Verified
通过 Nishu Jain | 已更新 5 giorni fa | Data
人气

9.7 / 10

延迟

1,194ms

服务等级

100%

Health Check

N/A

返回所有讨论

post

Rapid account: Deleted
[deleted]
2 anni fa

how can i get all post detail in one fetch without getting it id of article

Rapid account: Deleted
[deleted] Commented 2 anni fa

sir but i code it in javascript’

Rapid account: Nishujain 199719 Vg Ifu FH Zx VZ
nishujain199719-vgIfuFHZxVZ Commented 2 anni fa

Hi there,

Yes, you can do this using python-sdk. Checkout the Github repository for it.

Installation: pip install medium-api

  • If you want to fetch all the articles written by an user, use the following code:
# Import libraries
import os
from medium_api import Medium

# Get RAPIDAPI_KEY from the environment
api_key = os.getenv('RAPIDAPI_KEY')

# Create a `Medium` Object
medium = Medium(api_key)

# Create an "User" Object using 'username'
user = medium.user(username="nishu-jain")

# Fetch user-written articles
user.fetch_articles()

# Iterate over user articles and print their title
for article in user.articles:
    print(article.title)
  • If you want to fetch the publication’s articles, use the following code
# Import libraries
import os
from datetime import datetime, timedelta
from medium_api import Medium

# Get RAPIDAPI_KEY from the environment
api_key = os.getenv('RAPIDAPI_KEY')

# Create a `Medium` Object
medium = Medium(api_key)

# Create a "Publication" Object
publication = medium.publication(publication_id="98111c9905da", save_info=False)

# Fetch publication articles published within last week's days
last_weeks_articles = publication.get_articles_between(
                                _from=datetime.now(), 
                                _to=datetime.now() - timedelta(days=7)
                            )

for article in last_weeks_articles:
    print(article.title, f'({article.published_at})')
  • If you want to fetch topfeed’s articles, use the following code
# Import libraries
import os
from medium_api import Medium

# Get RAPIDAPI_KEY from the environment
api_key = os.getenv('RAPIDAPI_KEY')

# Create a `Medium` Object
medium = Medium(api_key)

# Create a "TopFeeds" Object with mode="new"
topfeeds = medium.topfeeds(tag="relationships", mode="new")

# Fetch all the articles information
topfeeds.fetch_articles()

# Iterate over topfeeds articles and print their title
for article in topfeeds.articles:
    print(article.title)

For each article, you can access the information like this:

print('Title: ', article.title)
print('Subtitle: ', article.subtitle)
print('Author ID: ', article.author.user_id)
print('Publication ID: ', article.publication._id)
print('Claps: ', article.claps)
print('Voters/Fans: ', article.voters)
print('Word Count: ', article.word_count)
print('Responses Count: ', article.responses_count)
print('Reading Time: ', article.reading_time)
print('Tags: ', article.tags)
print('Topics: ', article.topics)
print('Language: ', article.lang)
print('Published At: ', article.published_at)
print('Last Modified At: ', article.last_modified_at)
print('Responses: ', len(article.response_ids))
print('Cover Image: ', article.image_url)
print('URL: ', article.url)

PS: Under the hood, this python sdk is running a for-loop for each article_id. It uses multi-threading to drastically speed up the process. You can implement the same in any language of your choice (like javascript and others).

If you need any additional assistance, please let me know 😃

And feel free to email me at nishu@mediumapi.com

Other Resources

加入讨论 - 在下面添加评论:

登录/注册以发布新的评论