Net :: Twitter :: Lite无法通过OAuth进行身份验证

时间:2012-06-27 13:47:52

标签: perl twitter oauth

我正在尝试回复我的推文。我使用Net :: Twitter :: Lite:

my $nt = Net::Twitter::Lite->new(%consumer_tokens, %access_tokens, legacy_lists_api=>1);
my $mentions = $nt->mentions();
print Dumper $mentions;

但之后我只有一个错误:无法通过OAuth进行身份验证。 有什么想法吗?

我可以发布推文: my $status = $nt->update({ status => 'some text' }); 但我无法得到答复。

更新

工作:

#!/usr/bin/perl
use warnings;
use strict;
use Net::Twitter::Lite;
use Data::Dumper;

my %consumer_tokens = (
consumer_key    => 'xxxxxxxxxxxxxxxxxxxxxxxx',
consumer_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
);
my %access_tokens=(
access_token => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
access_token_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
);

my $nt = Net::Twitter::Lite->new(%consumer_tokens, %access_tokens, legacy_lists_api=>1);

#217932132083970049
my $status = $nt->update({ status => 'Happy Perl People!' });
print Dumper $status;

不工作:

#!/usr/bin/perl
use warnings;
use strict;
use Net::Twitter::Lite;
use Data::Dumper;

my %consumer_tokens = (
consumer_key    => 'xxxxxxxxxxxxxxxxxxxxxxxx',
consumer_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
);
my %access_tokens=(
access_token => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
access_token_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
);

my $nt = Net::Twitter::Lite->new(%consumer_tokens, %access_tokens, legacy_lists_api=>1);

#217932132083970049
my $mentions = $nt->mentions();
print Dumper $mentions;

1 个答案:

答案 0 :(得分:0)

首先注册api并生成信息,修改脚本并列出

use strict;
use warnings;
use Net::Twitter::Lite;

my $nt = Net::Twitter::Lite->new(
  consumer_key        => 'key_here', #first 
  consumer_secret     => 'consumer_secret_here', #
  access_token        => 'access_token', #second, generate token 
  access_token_secret =>  'access_token_secret', # 
  legacy_lists_api => 0,
);

my $result = eval { $nt->update('otra prueba') };

warn "$@\n" if $@;