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.
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
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.
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>"
HEADER = {
'Authorization': 'Bearer {}'.format(TOKEN),
}
response = requests.get(URL, headers=HEADER)
pprint.pprint(response.json())
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