我正在使用WWW :: Mechanize.对于不需要身份验证的方法,我会像其他任何URL一样获取这些方法,然后使用perl
JSON模块解析出我想要的任何数据:
my $response = $mech->get('http://api.stackexchange.com/1.1/questions?fromdate=' . $lasthour) my $q = from_json($response->content())
我过去曾使用Mechanize登录网站,但Oauth的内容令人困惑,documentation is provided for using the API表明它适用于Web应用程序(需要使用StackExchange注册?).
特别是,我对notifications method感兴趣,但我希望正确的代码允许访问任何auth-required方法.
解决方法
你看过
Net::StackExchange2吗?
#for methods that require auth. my $se = Net::StackExchange2->new( { site=>"stackoverflow",access_token => '<THE ACCESS TOKEN>',key => '<YOUR APP KEY>' } );
它使用LWP :: UserAgent.即使您不想直接使用Net :: StackExchange2模块,您也很有可能找到一些好借用的示例代码.