Created
October 6, 2011 05:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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