0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ruby | Qiita API で1人のユーザーの全記事一覧を取得する

Last updated at Posted at 2022-05-13

100記事x100ページまで取得できるので、上限は1万記事。

Ruby

require 'net/https'
require 'uri'

(1..100).each do |i|
  uri = URI.parse("https://qiita.com/api/v2/users/#{ENV['USER_ID']}/items?page=#{i}&per_page=100")
  res = Net::HTTP.get_response(uri)

  puts res.response.body
end

コマンド実行例

USER_ID=yumainaura ruby qiita-post.rb | jq

Qiita API のTOKENを使って実行上限数対策をする場合の例

require 'net/https'
require 'uri'

(1..100).each do |i|
  uri = URI.parse("https://qiita.com/api/v2/users/#{ENV['USER_ID']}/items?page=#{i}&per_page=100")

  request = Net::HTTP::Get.new(uri.request_uri, {'Content-Type' =>'application/json', "Authorization" => "Bearer #{ENV['TOKEN']}"})

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  response = http.request(request)

  puts response.response.body
end

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?