Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access the StackExchange API authenticated methods from a perl script?

I'm using WWW::Mechanize. For the methods that do not require authentication, I get those as I would any other url, and then use the perl JSON module to parse out whatever data I want:

my $response = $mech->get('http://api.stackexchange.com/1.1/questions?fromdate=' . $lasthour)
my $q = from_json($response->content())

I've used Mechanize to log into websites in the past, but the Oauth stuff is confusing, and what documentation is provided for using the API suggests that it is intended for web applications (that require registration with StackExchange?).

In particular, I am interested in the notifications method though I would expect the correct code to allow access to any of the auth-required methods.

like image 619
John O Avatar asked Nov 04 '22 01:11

John O


1 Answers

Have you looked at Net::StackExchange2?

#for methods that require auth.
my $se = Net::StackExchange2->new(
    {
        site=>"stackoverflow",
        access_token => '<THE ACCESS TOKEN>' ,
        key => '<YOUR APP KEY>'
    }
);

It uses LWP::UserAgent. Even if you don't want to use the Net::StackExchange2 module directly, you have a good chance of finding some good example code to borrow from.

like image 91
Richard Bychowski Avatar answered Nov 15 '22 06:11

Richard Bychowski