Skip to content

Instantly share code, notes, and snippets.

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