首页 文章

使用 Perl 通过 api 在 tumblr 上发布几张图片

提问于
浏览
0

我试图通过 perl API 在 tumblr 中发布 3 张图片...

我有这个代码工作好一张图片:

use LWP::Authen::OAuth;
use Data::Dumper;

my $ua = LWP::Authen::OAuth->new(
            oauth_consumer_key => 'xxx',
            oauth_consumer_secret => 'xxx',
            oauth_token => 'xxx',
            oauth_token_secret => 'xxx',
    );
my $url  = 'http://publicpics.free.fr/856833_10151249956981150_1285625380_o.jpg';
my %elements = (  
  'type' => 'photo', 
  'source' =>  $url,
);

print Dumper (\%elements);
print $ua->post( 'http://api.tumblr.com/v2/blog/xxxx.tumblr.com/post', [%elements] )->as_string;

我使用这个 API 文档http://www.tumblr.com/docs/en/api/v2#发布

对于几张图片,你必须在参数数组中过去...所以我试试这个,但不要工作:

use LWP::Authen::OAuth;
use Data::Dumper;

my $ua = LWP::Authen::OAuth->new(
            oauth_consumer_key => 'xxx',
            oauth_consumer_secret => 'xxx',
            oauth_token => 'xxx',
            oauth_token_secret => 'xxx',
    );
my @url  = ( 'http://publicpics.free.fr/856833_10151249956981150_1285625380_o.jpg' );
my %elements = (  
  'type' => 'photo', 
  'data' =>  \@url,
);

print Dumper (\%elements);
print $ua->post( 'http://api.tumblr.com/v2/blog/xxxx.tumblr.com/post', [%elements] )->as_string;

我有这个回报:

$VAR1 = {
      'data' => [
                  'http://publicpics.free.fr/856833_10151249956981150_1285625380_o.jpg'
                ],
      'type' => 'photo'
    };
HTTP/1.1 400 Bad Request
Connection: close
Date: Sun, 03 Mar 2013 22:01:13 GMT
Server: Apache
Vary: Accept-Encoding
Content-Length: 92
Content-Type: application/json
Client-Date: Sun, 03 Mar 2013 22:01:13 GMT
Client-Peer: 66.6.36.55:80
Client-Response-Num: 1
P3P: CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
X-Tumblr-Usec: D=112074

{"meta":{"status":400,"msg":"Bad Request"},"response":{"errors":["Error uploading photo."]}}

1 回答

  • 1

    数据用于本地文件,使用可访问互联网的图像源

    my %elements = (  
      'type' => 'photo', 
      'source' =>  \@url,
    );
    

    问候,

相关问题