Medium

부분 유료
Verified
분류별 Nishu Jain | 업데이트됨 5 days ago | Data
인기

9.7 / 10

지연 시간

906ms

서비스 수준

100%

Health Check

N/A

모든 토론으로 돌아가기

post

Rapid account: Deleted
[deleted]
2 years ago

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

Rapid account: Deleted
[deleted] Commented 2 years ago

sir but i code it in javascript’

Rapid account: Nishujain 199719 Vg Ifu FH Zx VZ
nishujain199719-vgIfuFHZxVZ Commented 2 years ago

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

아래에 의견을 추가하고 토론에 참여하세요.

새 댓글을 게시하려면 로그인 / 가입