该脚本非常适用于 costum twitter URL 缩短器,但由于某种原因,它刚刚开始放置损坏的链接。现在所有的链接都被破坏了,即使是以前的链接也很好。它显示在 twitter domain.com/p(somenumber) 上,并在浏览器中打开该 URL,而不是重定向到帖子。我想问题出在这个 Perl 代码中,它在 twitter 上自动发布 wordpress 帖子。
#!/usr/bin/perl -s
use strict;
use Data::Dumper;
use XML::Simple;
use Net::Twitter;
use Scalar::Util 'blessed';
use WWW::Facebook::API;
use JSON::Any;
use lib '/var/www/perl/.';
use MyLib::DB;
use MyLib::Settings;
my $settings = new Settings();
my $config = $settings->getConfig();
my $db = new DB(
dsn =>$config->{sql_connection}->{dsn},
database =>$config->{sql_connection}->{database},
server =>$config->{sql_connection}->{server},
login =>$config->{sql_connection}->{login},
password =>$config->{sql_connection}->{password}
);
my %posts = $db->getList('select * from add_ready_post where wp_id > ( select max(wp_id) from add_ready_post where is_sent=1 ) and post_title <> "" limit 1;');
my $nt = Net::Twitter->new(legacy => 0);
my $nt = Net::Twitter->new(
traits => [qw/OAuth API::REST/],
consumer_key => '',
consumer_secret => '',
access_token => '',
access_token_secret => '',
);
map {
my $message = $posts{$_}[4];
my $id = $posts{$_}[0];
my $url = ' domain.com/p' . $posts{$_}[1];
if ( $message ne '' )
{
# print 'Original: ' . $message . "\n";
if ( length( $message ) < 110 )
{
$message = $message . ".";
}
if ( length( $message ) > 110 )
{
$message = substr( $message, 0, 110 );
$message =~ /.*(\s\w+)$/i;
my $newMessage = substr( $message, 0, index( $message, $1 ) );
$message = $newMessage . '...';
}
# print 'Result : ' . $message . $url . "\n";
my $result = $nt->update( $message . $url );
# print Dumper( $result );
# print "\n";
my $sql = "UPDATE add_ready_post SET is_sent=1 WHERE id=" . int( $id ) . ";";
$db->execute( $sql );
}
} keys %posts;