Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get access token via facebook oauth. API key and API secret are saved with Config::Pit.
# -*- coding: utf-8 -*-
require 'rubygems'
require 'net/https'
require 'pit'
OAUTH_DOMAIN = 'graph.facebook.com' # ホスト名
OAUTH_PATH = '/oauth/access_token' # パス
OAUTH_QUERY_APIKEY = 'client_id' # API Keyのクエリパラメータ
OAUTH_QUERY_APISEC = 'client_secret' # API secret のクエリパラメータ
OAUTH_QUERY_TYPE = 'grant_type=client_credentials' # 固定
config = Pit.get("wt_test", :require => {
"api_key" => "Your App ID / API Key",
"api_secret" => "App Secret"
})
https = Net::HTTP.new(OAUTH_DOMAIN, 443)
https.use_ssl = true;
https.verify_mode = OpenSSL::SSL::VERIFY_NONE # 安全ではない?
result = https.get(OAUTH_PATH + '?' +
OAUTH_QUERY_APIKEY + '=' + config['api_key'].to_s + '&' +
OAUTH_QUERY_APISEC + '=' + config['api_secret'].to_s + '&' +
OAUTH_QUERY_TYPE)
puts result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment