|
# Below are examples of how to initialize and use a Twitter::Client object for each Twitter user |
|
|
|
# Can initialize by passing in Hash of oauth_access information for the authenticated user driving calls |
|
# through Twitter4R |
|
twitter = Twitter::Client.new(:oauth_access => { |
|
:key => ACCESS_KEY, :secret => ACCESS_SECRET }) |
|
# Can also initialize by loading in file configuration file and specifying YAML key name to use for user: |
|
twitter = Twitter::Client.from_config("file/name/to/config.yml", "key") # YAML file will look like twitter.yml |
|
|
|
##### STATUS APIs ###### |
|
# You can get a status by ID (old ID style, pre-snowflake update) |
|
status = twitter.status(:get, 107786772) |
|
# You can post a new status to Twitter as the authenticated user |
|
status = twitter.status(:post, "Using Ruby open source project Twitter4R version 0.7.0 to post this status update /cc @t4ruby #twitter4r") |
|
# You can delete one of the acting user's status updates like so |
|
status = twitter.status(:delete, 107790712) |
|
# You can reply to another status update (tweet) keeping reply-to information |
|
status = twitter.status(:reply, :in_reply_to_status_id => 1390482942342, |
|
:status => "@t4ruby This new v0.7.0 release is da bomb! #ruby #twitterapi #twitter4r") |
|
# You can post latitude and longitude information with the Tweet (you can also use :place_id too). |
|
status = twitter.status(:post, "My brand new status in all its glory here tweeted from somewhere in Africa.", |
|
:lat => 0, :long => 0) |
|
|
|
##### ACCOUNT APIs ####### |
|
# You can find out about your account's rate limit information with |
|
account_info = twitter.account_info |
|
# This returns a Twitter::RateLimitStatus with following attributes: |
|
account_info.class.attributes # => [:remaining_hits, :hourly_limit, :reset_time_in_seconds, :reset_time] |
|
|
|
##### BLOCK APIs ###### |
|
screen_name = 'dictionary' |
|
twitter.block(:add, 'dictionary') |
|
twitter.block(:remove, 'dictionary') |
|
id = 1260061 |
|
twitter.block(:add, id) |
|
twitter.block(:remove, id) |
|
user = Twitter::User.find(id, client) |
|
twitter.block(:add, user) |
|
twitter.block(:remove, user) |
|
|
|
##### FAVORITES APIs ###### |
|
id = 126006103423 |
|
twitter.favorite(:add, id) |
|
twitter.favorite(:remove, id) |
|
status = Twitter::Status.find(id, client) |
|
twitter.favorite(:add, status) |
|
twitter.favorite(:remove, status) |
|
# Now favorites... |
|
statuses = client.favorites(:page => 2) |
|
|
|
##### FRIENDING API ###### |
|
screen_name = 'dictionary' |
|
twitter.friend(:add, 'dictionary') |
|
twitter.friend(:remove, 'dictionary') |
|
id = 1260061 |
|
twitter.friend(:add, id) |
|
twitter.friend(:remove, id) |
|
user = Twitter::User.find(id, client) |
|
twitter.friend(:add, user) |
|
twitter.friend(:remove, user) |
|
|
|
##### DIRECT MESSAGING API ##### |
|
twitter.message(:post, 'Are you coming over at 6pm for the BBQ tonight?', 'myfriendslogin') |
|
twitter.message(:post, 'Are you coming over at 6pm for the BBQ tonight?', user) |
|
message = @twitter.message(:post, 'Are you coming over at 6pm for the BBQ tonight?', 1234567890) |
|
puts message.id, message.recipient, message.sender, message.text, message.geo, message.created_at |
|
|
|
##### SEARCH APIs ##### |
|
twitter.search(:q => "twitter4r") |
|
# various other options available too...TODO. In meantime, ask @SusanPotter questions |
|
|
|
##### TIMELINE APIs ##### |
|
twitter.timeline_for(:user, :id => "SusanPotter", :since_id => 107244390145204224) do |tweet| |
|
# do something interesting with each tweet |
|
end |
|
# various other options available too...TODO. In meantime, ask @SusanPotter questions |
|
|
|
##### TRENDS APIs ##### |
|
trends = twitter.trends # by default gets global trends |
|
puts trends.as_of |
|
trends.each { |t| puts t.name } |
|
|
|
# Other goodies too, but too tired to add examples now:) |