5

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.

5
  • ok, do you register your application? you must do that to use auth methods Commented Apr 1, 2013 at 19:40
  • I have now. What next? An answer with "this will only work after registration" and then instructions would have been welcome, I'd've upvoted that. Commented Apr 1, 2013 at 21:02
  • oh, I am not sure, what you want. What kind of application you have? Desktop or server side? Commented Apr 1, 2013 at 21:11
  • It's a plain perl script to be run from the command line or maybe cron. Commented Apr 2, 2013 at 5:24
  • so, you don't use this like server-side app and don't share it with anybody? just for yourself, yes? Commented Apr 2, 2013 at 8:01

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I think I might want to use this. Thank you, I don't know how it escaped my notice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.