帖子Photoset使用的tumblr API PHP [英] Post Photoset using Tumblr API PHP

查看:152
本文介绍了帖子Photoset使用的tumblr API PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想多张照片上传到一个photoset岗位的tumblr。我使用PHP来连接的tumblr和验证。我可以张贴个人照片和视频,但似乎无法弄清楚的photosets。还有对堆栈的其他职位,以帮助其他语言除了PHP。

我有照片的目录。我得到这些文件的内容,并使用SCANDIR把它们放到一个数组。但是,当我尝试发布该数组的tumblr,这是行不通的。

  $ scanned_directory =和array_diff(SCANDIR($目录),阵列('..',)'。');


  

$连接 - >后(博客/ $主机名/后,阵列('类型'=>'照片',
  国家'=> $ DEST,'链接'=> $ sourceurl,'源'=> $ sourceurl,
  '标题'=> $标题,'标签'=> $标签,'数据'=>
  $ scanned_directory));


我在做什么错了?

感谢您的帮助!


解决方案

我觉得你应该遍历$ scanned_directory变量,并确保你不正义的路径和文件名提交的tumblr的API,但实际内容与file_get_contents()函数的图像文件,工作的例子看起来可能是这样的:

 的foreach($ scanned_directory为$文件名){
    $数据[] =的file_get_contents($目录'/'$文件名);
}
$连接 - >后(博客/ $主机名/后,阵列('类型'=>'照片','国家'=> $ DEST,'链接'=> $ sourceurl,'源'= > $ sourceurl,'标题'=> $标题,'标签'=> $标签,'数据'= GT; $数据));

这应该有可能做的伎俩,只要确保$目录变量实际上是将图像目录的绝对路径(例如'/var/www/myhost.tld/public/images/photoset')

I am trying to upload multiple photos into a photoset post to Tumblr. I am using PHP to connect to Tumblr and authenticate. I can post individual photos and video but can't seem to figure out photosets. There are other posts on Stack that help other languages except for PHP.

I have a directory of photos. I get the contents of those file and put them into an array using scandir. But when I try to post that array to Tumblr, it doesn't work.

$scanned_directory = array_diff(scandir($directory), array('..', '.'));

$connection->post("blog/$hostname/post", array('type' => 'photo', 'state' => $dest, 'link' => $sourceurl, 'source' => $sourceurl, 'caption' => $caption, 'tags' => $tags , 'data' => $scanned_directory));

What am I doing wrong?

Thanks for the help!

解决方案

I think you should iterate the $scanned_directory variable and make sure you don't submit the just the path and filename to the Tumblr API, but the actual contents of your image file with file_get_contents(), a working example would look probably something like this:

foreach($scanned_directory as $filename){
    $data[] = file_get_contents($directory.'/'.$filename);
}
$connection->post("blog/$hostname/post", array('type' => 'photo', 'state' => $dest, 'link' => $sourceurl, 'source' => $sourceurl, 'caption' => $caption, 'tags' => $tags , 'data' => $data));

That should likely do the trick, just make sure the $directory variable is actually an absolute path to your image directory (e.g. '/var/www/myhost.tld/public/images/photoset')

这篇关于帖子Photoset使用的tumblr API PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆