Forked from seyhunak/twitter_application_bearer_token.rb
Last active
August 29, 2015 14:14
-
-
Save kripy/53ba379a3894e2cd0d69 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
consumer_key_secret = "#{Settings.twitter_key}:#{Settings.twitter_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' | |
begin | |
response = HTTParty.post('https://api.twitter.com/oauth2/token', body: body, headers: headers) | |
rescue Exception => e | |
return { code: 403, response: e.message } | |
end | |
if response.code == 200 | |
response['access_token'] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment