tumblrPHP
tumblrPHP copied to clipboard
Create a Photo Set
Hi Greg, thanks a lot for your code. I found it working perfectly to post a image with this code:
// Parameters
$parameters = array(
'type' => 'photo',
'state' => 'draft',
'tags' => 'test1,test2',
'slug' => 'slug-test',
'caption' => 'BOOOOOMMMMMM... Hello World. This is a test.',
'link' => 'https://example.com',
'source_url' => 'https://example.com/source',
'data'=> file_get_contents("/path/to/image.jpg")
);
$newpost = $tumblr->oauth_post("/blog/my-blog.tumblr.com/post",$parameters);
print_r($newpost);
That works perfect!
Now i am trying to send 2 pictures with the Array on the parameters:
// Parameters
$parameters = array(
'type' => 'photo',
'state' => 'draft',
'tags' => 'test1,test2',
'slug' => 'slug-test',
'caption' => 'BOOOOOMMMMMM... Hello World. This is a test.',
'link' => 'https://example.com',
'source_url' => 'https://example.com/source',
'data'=> array(file_get_contents("/path/to/image1.jpg"), file_get_contents("/path/to/image2.jpg"))
);
$newpost = $tumblr->oauth_post("/blog/my-blog.tumblr.com/post",$parameters);
print_r($newpost);
But it does not work. I get the following error:
stdClass Object ( [meta] => stdClass Object ( [status] => 401 [msg] => Not Authorized )[response] => Array ( ))
Do you know how can i send the 2 files in order to create the photo post?
according to this post, photosets should be supported by the V2.
i found a different solution for the problem here.
OAuth.php's build_http_query() need a bit of fix to support photosets as it seems it doesn't support another depth of array properly. I've replaced:
foreach ($value as $duplicate_value) {
$pairs[] = $parameter . '=' . $duplicate_value;
}
with:
$count = 0;
foreach ($value as $duplicate_value) {
$pairs[] = $parameter . '[' . $count . ']' . '=' . $duplicate_value;
$count++;
}
and it works like a charm. (The idea of the fix was from https://gist.github.com/codingjester/1649885 also)
By the way: Thanks Greg for the lib, it's a great help!
+1