Method: Twitter::REST::OAuth#token
- Defined in:
- lib/twitter/rest/oauth.rb
#token(options = {}) ⇒ String Also known as: bearer_token
Allows a registered application to obtain an OAuth 2 Bearer Token, which can be used to make API requests on an application's own behalf, without a user context.
Only one bearer token may exist outstanding for an application, and repeated requests to this method will yield the same already-existent token until it has been invalidated.
24 25 26 27 28 29 30 31 32 |
# File 'lib/twitter/rest/oauth.rb', line 24 def token( = {}) = .dup [:bearer_token_request] = true [:grant_type] ||= "client_credentials" url = "https://api.twitter.com/oauth2/token" headers = Twitter::Headers.new(self, :post, url, ).request_headers response = HTTP.headers(headers).post(url, form: ) response.parse["access_token"] end |