[First API] Try to get Qiita articles with Python


Since I hit the API for the first time, I will leave it as a personal memorandum.

This time I only got the data, but I would like to try various things in the future.

Obtaining an access token

Get an access token to use Qiita's API.

An access token is like a license that determines if you are an API user.

Regarding the issuing method, first access your own page of Qiita and then


From the settings on the above screen, go to the settings screen and


Click on the application


I have already issued it, but I will issue an access token from the personal access token.

You will see a random alphanumeric column, so be sure to make a note of it

Check operation on command line

First check if you can get it by using the curl command on the command line.

curl -s -H "Authorization: Bearer <The value of the access token>" https://qiita.com/api/v2/authenticated_user/items
C:\>curl -s -H "Authorization: Bearer <Access token value>" https://qiita.com/api/v2/authenticated_user/items
[{"rendered_body":"\n\u003ch2\u003e\n\u003cspan id=\"Introduction\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E3%81%AF%E3%81%98%E3%82%81%E3%81%AB\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003eIntroduction\u003c/h2\u003e\n\n\u003cp\u003e It is sent as a personal memorandum.\u003c/p\u003e\n\n\u003ch2\u003e\n\u003cspan id=\"When I woke up\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E8%B5%B7%E3%81%8D%E3%81%9F%E3%81%93%E3%81%A8\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e What happened\u003c/h2\u003e\n\n\u003cp\u003e p to remote repository ...

Omitted because it is long. .. However, it seems to be taken.

Implement in Python

Now that it's command-based, run it via python.

When I was researching, I found a god tool that converts curl commands to python, so I am based on this. (Oh, I haven't done anything like implementation.)

Site that converts curl commands to python

I modified the converted one a little and it became as follows.

import requests
import json
import pprint

URL = "https://qiita.com/api/v2/items"
TOKEN = "<Access token value>"
    'Authorization': 'Bearer {}'.format(TOKEN),

response = requests.get(URL, headers=HEADER)

I'm using pprint to clean it up a bit

When I run it

・ ・ ・
  'title': '[Serverless Framework]Monorepo using yarn workspace',
  'updated_at': '2020-12-28T19:26:14+09:00',
  'url': 'https://qiita.com/allJokin/items/9316e5384a3bf7a4536b',
  'user': {'description': None,
           'facebook_id': None,
           'followees_count': 0,
           'followers_count': 0,
           'github_login_name': 'allJokin',
           'id': 'allJokin',
           'items_count': 1,
           'linkedin_id': None,
           'location': None,
           'name': '',
           'organization': None,
           'permanent_id': 600358,
           'profile_image_url': 'https://s3-ap-northeast-1.amazonaws.com/qiita-image-store/0/600358/8d5eba69a13ba6bef9ae50d23c9a1fa3e87b60ae/large.png?1607605958',
           'team_only': False,
           'twitter_screen_name': 'AllJokin',
           'website_url': None}}]
・ ・ ・

It looks like it's taken! !!


python 3.8.0 requests 2.25.1


I couldn't understand the API specifications at all and could only bring all the article information. .. I want to read more and be able to master it. Also, this time I'm hard-coding, but I'd like to think about managing config.

Next, I will challenge Amazon's API.

Recommended Posts

[First API] Try to get Qiita articles with Python
Try logging in to qiita with Python
I tried to get the authentication code of Qiita API with Python.
Get the number of articles accessed and likes with Qiita API + Python
[Python] Get user information and article information with Qiita API
Get a list of articles posted by users with Python 3 Qiita API v2
Link to get started with python
Get reviews with python googlemap api
Try to operate Facebook with Python
Quine Post with Qiita API (Python)
How to get started with Python
Get Qiita trends with Python scraping
The first API to make with python Djnago REST framework
Get stock articles of infrastructure engineer yuta with Qiita API
Try to reproduce color film with Python
Get the number of PVs of Qiita articles you posted with API
After hitting the Qiita API with Python to get a list of articles for beginners, we will visit the god articles
First YDK to try with Cisco IOS-XE
[Python] Get Python package information with PyPI API
Try to get CloudWatch metrics with re: dash python data source
Try to create a Qiita article with REST API [Environmental preparation]
[Python] To get started with Python, you must first make sure you can use Python.
POST photos with Microsoft Bing Image Search API to get Image Insights (Python)
I tried to get the movie information of TMDb API with Python
First steps to try Google CloudVision in Python
Try to solve the man-machine chart with Python
Try to draw a life curve with python
Get stock price data with Quandl API [Python]
I tried to get CloudWatch data with Python
Try to make a "cryptanalysis" cipher with Python
Try to automatically generate Python documents with Sphinx
How to get article data using Qiita API
Recent ranking creation using Qiita API with Python
Try to make a dihedral group with Python
Get Gmail subject and body with Python and Gmail API
[Introduction to Udemy Python3 + Application] 9. First, print with print
[Python] Mention to multiple people with Slack API
A layman wants to get started with Python
Try using ChatWork API and Qiita API in Python
[Cloud102] # 1 Get Started with Python (Part 1 Python First Steps)
Python script to get note information with REAPER
Try to detect fish with python + OpenCV2.4 (unfinished)
Try posting to Qiita for the first time
Try scraping with Python.
[Python] Get Qiita trends
Get date with python
Get users belonging to your organization from Garoon REST API with Python + Requests
Note: How to get the last day of the month with python (added the first day of the month)
Try to solve the programming challenge book with python3
Try to make a command standby tool with python
I tried to get started with blender python script_Part 01
Try to solve the internship assignment problem with Python
The first algorithm to learn with Python: FizzBuzz problem
Try to operate DB with Python and visualize with d3
Get schedule from Garoon SOAP API with Python + Zeep
Try to make RESTful API with MVC using Flask 1.0.2
I tried to get started with blender python script_Part 02
Try to get the contents of Word with Golang
Python beginners get stuck with their first web scraping
How to get mouse wheel verdict with Python curses
Try to automate pdf format report creation with Python