Skip to content

Instantly share code, notes, and snippets.

@yazumoto
Last active October 14, 2015 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yazumoto/df1c4495bd2371b1e625 to your computer and use it in GitHub Desktop.
Save yazumoto/df1c4495bd2371b1e625 to your computer and use it in GitHub Desktop.
RubyでZaim APIを利用する ref: http://qiita.com/seteen/items/12f535228e2a3453764b
require 'oauth'
CONSUMER_KEY = '1で取得したConsumer Key'
CONSUMER_SECRET = '1で取得したConsumer Secret'
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET,
site: 'https://api.zaim.net',
request_token_path: '/v2/auth/request',
authorize_url: 'https://auth.zaim.net/users/auth',
access_token_path: '/v2/auth/access')
request_token = consumer.get_request_token(oauth_callback: 'http://google.com')
system('open', request_token.authorize_url)
print "Verifierを入力してください:"
oauth_verifier = gets.chomp.strip
access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)
p access_token.token
p access_token.secret
require 'oauth'
require 'json'
CONSUMER_KEY = '1で取得したCONSUMER KEY'
CONSUMER_SECRET = '1で取得したCONSUMER SECRET'
ACCESS_TOKEN = '2で取得したACCESS TOKEN'
ACCESS_TOKEN_SECRET = '2で取得したACCESS TOKEN SECRET'
API_URL = 'https://api.zaim.net/v2/'
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET,
site: 'https://api.zaim.net',
request_token_path: '/v2/auth/request',
authorize_url: 'https://auth.zaim.net/users/auth',
access_token_path: '/v2/auth/access')
access_token = OAuth::AccessToken.new(consumer, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# 認証できているかを確認
verify = access_token.get("#{API_URL}home/user/verify")
p JSON.parse(verify.body)
# カテゴリの取得
categories = access_token.get("#{API_URL}home/category")
p JSON.parse(categories.body)
# ジャンルの取得
genres = access_token.get("#{API_URL}home/genre")
p JSON.parse(genres.body)
# 出金(食料品)
access_token.post("#{API_URL}home/money/payment", category_id: 101, genre_id: 10101, amount: 12345)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment