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

使用perl通过API在tumblr上发布本地映像文件,第1张

概述我一直在用perl搞乱tumblr API,并且已经有了几个功能. 但是,我无法通过perl上传本地图像文件. 这是我的代码适用于URL use LWP::Authen::OAuth; use JSON; use Data::Dumper; use strict; my $ua = LWP::Authen::OAuth->new( 我一直在用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”替换为post参数中的“data”时(按照其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”添加到请求标头中.

总结

以上是内存溢出为你收集整理的使用perl通过API在tumblr上发布本地映像文件全部内容,希望文章能够帮你解决使用perl通过API在tumblr上发布本地映像文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1269270.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存