Created
July 21, 2014 08:07
-
-
Save seyhunak/4ea28d9858a9a346dd6d to your computer and use it in GitHub Desktop.
Twitter - HTTParty - Application Only Token
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