我正试图通过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."]}}
答案 0 :(得分:1)
数据用于本地文件,使用可访问互联网的图像源
my %elements = (
'type' => 'photo',
'source' => \@url,
);
此致