Skip to content

Instantly share code, notes, and snippets.

@yoozoosato
Created October 6, 2011 05:15
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 yoozoosato/1266575 to your computer and use it in GitHub Desktop.
Save yoozoosato/1266575 to your computer and use it in GitHub Desktop.
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