🖥

Qiita API で自分のユーザー情報を取得するRubyのスクリプト例

2019/01/31に公開

Qiita API で自分のユーザー情報を取得するRubyのスクリプト例

TOKEN=xxxxxx ruby example.rb
require 'net/https'
require 'uri'

path = 'https://qiita.com/api/v2/authenticated_user'

uri = URI.parse(path)
http = Net::HTTP.new(uri.host, uri.port)

http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

req = Net::HTTP::Get.new(uri.request_uri)
req["Authorization"] = "Bearer #{ENV['TOKEN']}"

res = http.request(req)
puts res.code, res.msg
puts res.body

結果

200
OK
{"description":"Web系。Ruby とか。 いなうらゆうま / YumaInaura / 稲浦悠馬","facebook_id":"yumainaura","followees_count":89,"followers_count":136,"github_login_name":"YumaInaura","id":"YumaInaura","items_count":1009,"linkedin_id":"","location":"Osaka","name":"Inaura いなうら 稲浦 Yuma ゆうま 悠馬","organization":"","permanent_id":89618,"profile_image_url":"https://qiita-image-store.s3.amazonaws.com/0/89618/profile-images/1546214964","team_only":false,"twitter_screen_name":"YumaInaura","website_url":"http://twitter.com/yumainaura","image_monthly_upload_limit":104857600,"image_monthly_upload_remaining":85146345}

チャットメンバー募集

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

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-01-31

Discussion