lib/twitter/rest/oauth.rb
# 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.
#
# @see https://dev.twitter.com/rest/reference/post/oauth2/token
# @rate_limited No
# @authentication Required
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [String] The Bearer token.
# @param options [Hash] A customizable set of options.
# @example Generate a Bearer Token
#   client = Twitter::REST::Client.new(consumer_key: 'abc', consumer_secret: 'def')
#   bearer_token = client.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.
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 .
def token(options = {})
        options = options.dup
        options[:bearer_token_request] = true
        options[:grant_type] ||= 'client_credentials'
        url = 'https://api.twitter.com/oauth2/token'
        headers = Twitter::Headers.new(self, :post, url, options).request_headers
        response = HTTP.headers(headers).post(url, form: options)
        response.parse['access_token']
      end
def token ( options = { } ) options = options . dup options [ :bearer_token_request ] = true options [ :grant_type ] ||= 'client_credentials' url = 'https://api.twitter.com/oauth2/token' headers = Twitter :: Headers . new ( self , :post , url , options ) . request_headers response = HTTP . headers ( headers ) . post ( url , form : options ) response . parse [ 'access_token' ] end
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.
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 .
The Bearer token.
The Bearer token .
String
[Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
[ Twitter :: Error :: Unauthorized ] Error raised when supplied user credentials are not valid .
options
A customizable set of options.
A customizable set of options .
see
None
rate_limited
None
authentication
None
example
Generate a Bearer Token client = Twitter::REST::Client.new(consumer_key: 'abc', consumer_secret: 'def') bearer_token = client.token
Generate a Bearer Token client = Twitter :: REST :: Client . new ( consumer_key : ' abc ' consumer_secret : ' def ' ) bearer_token = client . token