首页 文章

使用 Tumblr API PHP 发布 Photoset

提问于
浏览
0

我正在尝试将多张照片上传到 Tumblr 的 photoset 帖子中。我正在使用 PHP 连接到 Tumblr 并进行身份验证。我可以发布个人照片和视频,但似乎无法弄清楚照片。 Stack 上还有其他帖子可以帮助除 PHP 之外的其他语言。

我有一个照片目录。我得到这些文件的内容,并使用 scandir 将它们放入一个数组中。但是当我尝试将该数组发布到 Tumblr 时,它不起作用。

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

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

我究竟做错了什么?

谢谢您的帮助!

1 回答

  • 2

    我认为你应该迭代$scanned_directory 变量,并确保你不提交 Tumblr API 的路径和文件名,但是带有 file_get_contents()的图像文件的实际内容,一个工作示例看起来可能是这样的:

    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));
    

    这应该可以解决问题,只需确保$directory 变量实际上是图像目录的绝对路径(e.g. '/var/www/myhost.tld/public/images/photoset')

相关问题