Changes

Jump to: navigation, search

C4LN 2012: Intro to the Twitter API

1,193 bytes added, 16:24, 24 May 2012
+getting started on code
=== Authorize the App on your Bot's Account === 
While still logged in under the bot's account, navigate to the app's page and generate your access token:
* '''<tt>access_token_secret</tt>'''
 
 
== Getting started on the code ==
 
Each Twitter API library is going to have its own way to get initialized and set up. Usually it's going to start with creating an object to represent your connection to Twitter and feeding it ALL THE KEYS.
 
my $twitter = Net::Twitter->new(
traits => [qw/API::REST OAuth/],
consumer_key => $conf{'consumer_key'},
consumer_secret => $conf{'consumer_secret'},
access_token => $conf{'access_token'},
access_token_secret => $conf{'access_token_secret'},
);
 
...and then you'll be able to use the library methods to do the things that you might want to do.
== Rules of the Road ==
== Getting started on the code ==
Each Twitter API library is going == General things you may want to have its own way to get initialized and set up. do ==
=== Tweet updates from elsewhere ===
twitter = TwitterConnection.new()
at (interval) { msg == General things you may want to do ==fetch_external_resource; msg.truncate_to_140_chars; twitter->update(msg) }
=== Check for @-messages and reply ===
twitter =TwitterConnection.new()   mentions =twitter->mentions( since_id = Tweet updates from elsewhere > last_mention )  at (interval) { foreach mention in mentions { mention.parse mention.reply last_mention =mention.id } }  sub reply(mention) { msg =fetch_external_resource()  msg = '@' + mention.sending_user->screen_name + ' ' + msg msg.truncate_to_140_chars twitter->update(msg, in_reply_to => mention) } 
22
edits

Navigation menu