Andy
Andy

Reputation: 11008

How to add geolocation to a tweet in Rails?

At the moment my Rails app can tweet via twitter gem, and I would like to add a geotag to my tweets. The geolocation is constant. How can I do this?

Twitter::Client.new.update('Hello, there!')

Upvotes: 0

Views: 497

Answers (1)

Ben Moss
Ben Moss

Reputation: 179

Twitter.configure do |config|
  config.consumer_key = YOUR_CONSUMER_KEY
  config.consumer_secret = YOUR_CONSUMER_SECRET
  config.oauth_token = YOUR_OAUTH_TOKEN
  config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end

# Initialize your Twitter client
client = Twitter::Client.new

# Post a status update
client.update("I just posted a status update via the Twitter Ruby Gem!", {:lat => 38.89859, :long => -77.035971})

The user has to have checked the "Add a location to your tweets" option in their settings (aka geo_enabled)

Source: Twitter Gem API

Upvotes: 2

Related Questions