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#posting

对于几张图片,您必须在参数中传递一个数组......所以我试试这个但不工作:

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."]}}
4

1 回答 1

1

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

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

问候,

于 2013-03-04T10:11:12.037 回答