Created
January 9, 2015 11:17
-
-
Save jingkaihe/c9ad3f8e1d70005ecbed to your computer and use it in GitHub Desktop.
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
require 'yaml' | |
require 'httparty' | |
def get_secret | |
secret_file = File.expand_path('../.secret.yml', __FILE__) | |
YAML.load_file(secret_file) | |
end | |
secret = get_secret | |
consumer_key_secret = "#{secret["CONSUMER_KEY"]}:#{secret["CONSUMER_SECRET"]}" | |
encoded_key_secret = Base64.strict_encode64(consumer_key_secret) | |
headers = { | |
'Authorization' => "Basic #{encoded_key_secret}", | |
'Content-Type' => "application/x-www-form-urlencoded;charset=UTF-8" | |
} | |
body = 'grant_type=client_credentials' | |
response = HTTParty.post('https://api.twitter.com/oauth2/token', body: body, headers: headers) | |
puts response["access_token"] if response.code == 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment