gpt4 book ai didi

perl - 使用 perl 通过 API 在 tumblr 上发布本地镜像文件

转载 作者:行者123 更新时间:2023-12-03 17:52:59 26 4
gpt4 key购买 nike

我一直在用 perl 处理 tumblr API,并且已经得到了几个可以工作的函数。

但是,我无法通过 perl 获取要上传的本地镜像文件。

这是我的适用于 URL 的代码

    use LWP::Authen::OAuth;
use JSON;
use Data::Dumper;
use strict;
my $ua = LWP::Authen::OAuth->new(
oauth_consumer_key => 'xxx',
oauth_consumer_secret => 'xxx',
oauth_token => 'xxx',
oauth_token_secret => 'xxx',
);




my $response;
$response = $ua->post( 'http://api.tumblr.com/v2/blog/mytumblr.tumblr.com/post', [
type => 'photo',
url => 'http://www.example.com/mypic.jpg' ,
caption => 'Test image 1',
]);


if ($response->is_success) {
print "it worked";
}
else {
print "it did not work \n \n \n \n";
print $response->as_string;
}

但是,当我在帖子参数中将“数据”替换为“url”时(按照此处的 API 描述 - http://www.tumblr.com/docs/en/api/v2#posting 中的说明),我不断收到来自 tumblr 的错误响应。我尝试了几种输入“数据”参数的方法 - 作为文件的路径,作为二进制表示,作为 URL 编码的二进制表示,作为 url 编码的 base64 二进制表示,将这些值之一作为唯一元素卡住在一个数组中 - 我已经尝试了所有,并且每个我都从 tumblr 收到一条错误消息。

那么,有人可以告诉我如何将本地镜像文件上传到 tumblr 吗?

最佳答案

我对 tumblr API 并不完全熟悉,但是通过谷歌搜索找到了这个例子:https://gist.github.com/derekg/1198576

我会尝试

$response = $ua->post( 'http://api.tumblr.com/v2/blog/mytumblr.tumblr.com/post', [
type => 'photo',
'data[0]' => $file_contents , ## LWP::Useragent should automatically urlencode this
caption => 'Test image 1',
]);

根据这个答案 https://stackoverflow.com/a/177866/810448 ,“data[]”可能也适用于这种情况。

如果 LWP::Useragent 尚未执行此操作,我还会考虑将“Content-type: application/x-www-form-urlencoded”添加到请求 header 中。

关于perl - 使用 perl 通过 API 在 tumblr 上发布本地镜像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16575174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com