Skip to content

Instantly share code, notes, and snippets.

@ms2sato
Created May 1, 2014 23:25
Show Gist options
  • Save ms2sato/11464297 to your computer and use it in GitHub Desktop.
Save ms2sato/11464297 to your computer and use it in GitHub Desktop.
require 'twitter'
namespace :twitter do
desc "ツイートする"
task :tweet => :environment do
## アプリ登録時に取得したCONSUMER_KEY/CONSUMER_SECRET
CONSUMER_KEY = 'xxxxx'
CONSUMER_SECRET = 'xxxxx'
## irbで取得したAccess Token/Access Secret
OAUTH_TOKEN = 'xxxxx'
OAUTH_TOKEN_SECRET = 'xxxxx'
config = {
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET,
:oauth_token => OAUTH_TOKEN,
:oauth_token_secret => OAUTH_TOKEN_SECRET
}
client = Twitter::REST::Client.new(config)
tweet = "from service. this is test. "
update(client, tweet)
end
def update(client, tweet)
begin
tweet = (tweet.length > 140) ? tweet[0..139].to_s : tweet
client.update(tweet.chomp)
rescue => e
Rails.logger.error "<<twitter.rake::tweet.update ERROR : #{e.message}>>"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment