Created
May 19, 2009 08:59
-
-
Save typester/113991 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package MyApp::Controller::Root; | |
| use strict; | |
| use warnings; | |
| use parent 'Catalyst::Controller'; | |
| __PACKAGE__->config->{namespace} = ''; | |
| use Net::Twitter::OAuth; | |
| my $client = Net::Twitter::OAuth->new( | |
| consumer_key => "G6f8KnnBWp4oyVA72ulPTQ", | |
| consumer_secret => "ybPBPEuMJvgGwRZHma3KfMJ1R5rGVPEHNgQHFUuy1M8", | |
| ); | |
| my ($access_token, $access_token_secret); | |
| sub twitter_authorize :Local { | |
| my ($self, $c) = @_; | |
| my $url = $client->oauth->get_authorization_url; | |
| $c->response->cookies->{oauth} = { | |
| value => { | |
| token => $client->oauth->request_token, | |
| token_secret => $client->oauth->request_token_secret, | |
| }, | |
| }; | |
| $c->response->redirect($url); | |
| } | |
| sub twitter_auth_callback : Local { | |
| my($self, $c) = @_; | |
| my %cookie = $c->request->cookies->{oauth}->value; | |
| $client->oauth->request_token($cookie{token}); | |
| $client->oauth->request_token_secret($cookie{token_secret}); | |
| ($access_token, $access_token_secret) | |
| = $client->oauth->request_access_token; | |
| } | |
| sub make_tweet : Local { | |
| my($self, $c) = @_; | |
| $client->oauth->access_token($access_token); | |
| $client->oauth->access_token_secret($access_token_secret); | |
| # Now you can call any Net::Twitter API methods on $client | |
| my $status = $c->req->param('status'); | |
| my $res = $client->update({ status => $status }); | |
| } | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment