BusyBird
view release on metacpan or search on metacpan
lib/BusyBird/Manual/Tutorial.pod view on Meta::CPAN
Note that if you already use the TCP port 5000, C<busybird> command fails with "Address already in use" error.
In that case, try another port by C<-p> option.
$ busybird -p 4444
You can see complete list of options by C<-h> option.
$ busybird -h
=head1 Input Statuses
By default, your L<BusyBird> instance has a timeline called "home", but the timeline has no status yet.
It won't magically import statuses out of nowhere.
You must input statuses to it.
To input statuses, you can use L<BusyBird>'s Web API.
$ curl -d '{"text":"hello, world!"}' http://127.0.0.1:5000/timelines/home/statuses.json
C<< POST /timelines/home/statuses.json >> endpoint inputs statuses to the "home" timeline.
Statuses are in the HTTP request body, encoded in JSON.
You can input more than one statuses by posting an array of statuses. Here is a bit more complicated example.
$ curl \
-d '[{"text":"Hello, Bob!", "user":{"screen_name":"Alice"}}, {"text":"Hello, Alice!", "user":{"screen_name":"Bob"}}]' \
http://127.0.0.1:5000/timelines/home/statuses.json
This time, the statuses have C<user.screen_name> fields.
L<BusyBird> renders this field as the person or object that created the status.
=head2 Import RSS/Atom Feeds
You now understand how to input statuses to L<BusyBird>, but it is boring to create statuses by hand.
So let's import RSS/Atom feeds into L<BusyBird>. It's very easy!
=over
=item 1.
Install another module L<BusyBird::Input::Feed>.
$ cpanm BusyBird::Input::Feed
=item 2.
Then, run L<busybird_input_feed> command bundled with the module.
$ busybird_input_feed https://metacpan.org/feed/recent -p http://127.0.0.1:5000/timelines/home/statuses.json
=back
After that, you can see the imported feed items (in this case, Perl modules recently uploaded) on L<BusyBird>.
Try repeating the command above.
You will see that L<BusyBird> only accepts the new statuses that are not yet in L<BusyBird>'s timeline.
In a L<BusyBird> timeline, all statuses must have unique C<id> field.
If you input a status that is already in the timeline, that status is ignored.
This means you can repeat the above command without worrying about duplicate statuses.
Register the command with C<cron>, then the L<BusyBird> timeline is automatically synchronized to
the latest state of the feed.
=head2 Import Statuses from Twitter
Next, let's import statuses (tweets) from L<Twitter|https://twitter.com/> and view them on L<BusyBird>.
That's a bit more tricky than importing feeds because it requires authentication.
To import tweets from Twitter via its API, you have to get the B<tokens> first. Here is how to get the tokens.
=over
=item 1.
Access L<https://apps.twitter.com/>.
=item 2.
"Sign in" with your Twitter account.
=item 3.
Click "Create New App" button.
=item 4.
Fill the form and click "Create your Twitter application".
=item 5.
Click "API Keys" tab.
=item 6.
Click "Create my access token" button at the bottom of the page.
You may have to refresh the page to get the created token.
=item 7.
Now in "API Keys" page, you see four mysterious tokens:
B<< API key >>, B<< API secret >>, B<< Access token >> and B<< Access token secret >>.
=back
The procedure above may be out of date. The point is to get the four OAuth tokens.
B<< Make sure to keep the four tokens (especially the "secret" ones) secret >>. Those are like the username-password pair of your account.
Now that you have access to Twitter API, let's write a script called C<"import.pl"> to import tweets.
## File: import.pl
use strict;
use warnings;
use Net::Twitter::Lite::WithAPIv1_1;
use JSON;
my $nt = Net::Twitter::Lite::WithAPIv1_1->new(
consumer_key => "API_KEY",
consumer_secret => "API_SECRET",
( run in 0.684 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )