Git Product home page Git Product logo

Comments (16)

jeflopodev avatar jeflopodev commented on July 19, 2024

Hi, I have the same problem when going to create a photoset. I've created an stackoverflow question about this issue. The unique diference is that i'm not grabbing the images from a local path, im getting the the xml output. using simplexml object to get the array of images.

http://stackoverflow.com/questions/18821638/how-to-create-a-photoset-with-tumblr-api-v2

from tumblr.php.

seejohnrun avatar seejohnrun commented on July 19, 2024

This client currently does not support photosets.
I'll try to get something together today and send a pull request

from tumblr.php.

komapa avatar komapa commented on July 19, 2024

Thanks JC!

On Sep 16, 2013, at 11:48 AM, John Crepezzi [email protected] wrote:

This client currently does not support photosets.
I'll try to get something together today and send a pull request


Reply to this email directly or view it on GitHub.

from tumblr.php.

jeflopodev avatar jeflopodev commented on July 19, 2024

I tried to use the code of this pull request #19 but I can't get it to work.

I'm wondering if just works with local file paths or if it also works with externals URL's, lets suppose an xml structure:

<photoset>
    <photo>
        <photo-url>http://25.media.tumblr.com/2613911823e2a1700f9720ead6d630c0/tumblr_mt1i4skCQs1qmayvjo1_400.jpg</photo-url>
    </photo>
    ... more photo elements ...
</photoset>

This is the kind of structure we can find If we parse the response of ie. http://truckyeahcountrystars.tumblr.com/api/read?type=photo&num=50

So what I've done is to parse it as SimpleXML object and take the array:

foreach($post->{'photoset'}->{'photo'} as $photo){
    $photos[] = (string) $photo->{'photo-url'}[0]; // index 0 is the highest resolution image...
}
$options = array('type' => 'photo', 'tags' => 'Test1, Test2', 'data' => $photos);

And a var_dump of $photos throw:

array(2) { [0]=> string(94) "http://25.media.tumblr.com/2613911823e2a1700f9720ead6d630c0/tumblr_mt1i4skCQs1qmayvjo1_400.jpg" [1]=> string(94) "http://31.media.tumblr.com/059f8b305337f0fbf25b83346a1223c5/tumblr_mt1i4skCQs1qmayvjo2_400.jpg" } 

And PHP throws:

Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open http://25.media.tumblr.com/2613911823e2a1700f9720ead6d630c0/tumblr_mt1i4skCQs1qmayvjo1_400.jpg for reading' in C:\xampp\htdocs\standalone-projects\Tumblr\Bot\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php:50 Stack trace: #0 C:\xampp\htdocs\standalone-projects\Tumblr\Bot\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php(26): Guzzle\Http\Message\PostFile->setFilename('http://25.media...') #1 C:\xampp\htdocs\standalone-projects\Tumblr\Bot\vendor\guzzle\guzzle\src\Guzzle\Http\Message\EntityEnclosingRequest.php(200): Guzzle\Http\Message\PostFile->__construct('data[0]', 'http://25.media...', NULL) #2 C:\xampp\htdocs\standalone-projects\Tumblr\Bot\vendor\guzzle\guzzle\src\Guzzle\Http\Message\EntityEnclosingRequest.php(225): Guzzle\Http\Message\EntityEnclosingRequest->addPostFile('data[0]', 'http://25.media...', NULL, false) #3 C:\xampp\htdocs\standalone-projects\Tumblr\Bot\src\Tumblr\API\RequestHandl in C:\xampp\htdocs\standalone-projects\Tumblr\Bot\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php on line 50

So, how I should pass the images to the 'data' argument ?

UPDATE:

Excuse me because I'm quite noob... but, I've been reading the vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php setFilename() (the function that threw the exception). The error is that I need to pass just the filename and not the whole path ? If it is true, it couldn't be done with the URL right ? I'll need to download the resources and specify just its filenames. !¿

from tumblr.php.

seejohnrun avatar seejohnrun commented on July 19, 2024

@jeflopo what you're looking for (to avoid downloading and re-uploading the image) is the source parameter. Currently it doesn't take an array as an arg, but it should - and I'll update the pull request to reflect that change

from tumblr.php.

seejohnrun avatar seejohnrun commented on July 19, 2024

Updated

from tumblr.php.

jeflopodev avatar jeflopodev commented on July 19, 2024

I've read this two attributes (data and source) for photo posts in http://www.tumblr.com/docs/en/api/v2#posting
But the docs specify "String" as type for "source". Then I thought that would be only one string...

Do you mean that this parameter (source) would also accept an array of strings ?

if ($post->{'photoset'}) {
    foreach($post->{'photoset'}->{'photo'} as $photo){
        $photos[] = (string) $photo->{'photo-url'}[0];
    }
    $data = array('type' => 'photo', 'tags' => 'Test1, Test2', 'source' => $photos);
} else {
    $data = array('type' => 'photo', 'tags' => 'Test1, Test2', 'source' => (string) $post->{'photo-url'});
}

I can't get it to work, how I should pass multiple images to source if its type is "String" and using an array of strings throws:

Fatal error: Uncaught Tumblr\API\RequestException: [401]: Not Authorized thrown in C:\xampp\htdocs\standalone-projects\Tumblr\Bot\src\Tumblr\API\Client.php on line 434

The authorization process works when i'm just using a single image (the 'else' part). Only fails when I pass an array as its parameter value.

Thank you for updating it so fast ! You're great :)

from tumblr.php.

seejohnrun avatar seejohnrun commented on July 19, 2024

@jeflopo You need to be using the new code that was just added to #19 (and recently merged to master)
If so, can you var_dump $data and make sure it's of the right form (and maybe paste it here if it's not sensitive?

from tumblr.php.

jeflopodev avatar jeflopodev commented on July 19, 2024

@seejohnrun I've cloned the master branch and the code is identical to the repo. Checked it manually.

Here's the var $data:

$data = array('type' => 'photo', 'tags' => 'Test1, Test2', 'source' => $photos);

Here's the var_dump($data):

array(3) { ["type"]=> string(5) "photo" ["tags"]=> string(12) "Test1, Test2" ["source"]=> array(2) { [0]=> string(94) "http://25.media.tumblr.com/cb6342710cf21185bf265b60096478e8/tumblr_mt5gaxZyHA1qmayvjo1_400.jpg" [1]=> string(94) "http://31.media.tumblr.com/b70c53c0f735df1e7610a9a8d2bac6d5/tumblr_mt5gaxZyHA1qmayvjo2_400.jpg" } }

Still getting:

Fatal error: Uncaught Tumblr\API\RequestException: [401]: Not Authorized thrown in C:\xampp\htdocs\standalone-projects\Tumblr\Bot\src\Tumblr\API\Client.php on line 433

It's all correct ? I Can't understand why it throws the RequestException :$

UPDATE:
I've created a gist. A really straighforward example to illustrate the problem I have:
https://gist.github.com/jeflopo/6660517#file-tumblr1-php

Sorry, but the editor doesn't let me set 2 or 4 spaces to indentations, well... I can, but isn't applied :S

from tumblr.php.

seejohnrun avatar seejohnrun commented on July 19, 2024

I'll try to take a look at this tonight and get back to you!

from tumblr.php.

AbeCole avatar AbeCole commented on July 19, 2024

I've tried on many occasions to get multiple photos to upload using PHP, just interested if either of you two have managed to get a post actually up?

Never have a problem with any other post type or even with a single image in either 'data' or 'attribute', but every combination of getting the correct "URL-Encoded Binary Contents" hasn't worked.

Some people have said you have to do something like getting the hexadecimal contents then replace some characters. But if either of you have got this method working I'd love to know how!

Update: Got it working :) ! Using an array called 'source' containing local file path to images, need to edit files a little I'll try make a pull for it over the weekend.

from tumblr.php.

jeflopodev avatar jeflopodev commented on July 19, 2024

It works... Thank you both !! I've created a second gist to reflect the latest changes: https://gist.github.com/jeflopo/6889459

What I do is to register an app to grab the keys. Set them in the $keys array, the script parses the XML feed from a tumblr blog, then just detects if the post is single or photoset and handles the images for the $data array.

Is dead simple and doesn't follow any best practice xD but is functional.

You can see a photoset created with it in http://jtrash01.tumblr.com/post/63480921494/jtrash01-tumblr-com

from tumblr.php.

AbeCole avatar AbeCole commented on July 19, 2024

I've made a pull request here #20 then you can use the it like this:

$images = array('/var/www/images/1.jpg','/var/www/images/2.jpg','/var/www/images/3.jpg');

foreach ($images as $image)
{
    $photos[] = $image;
}

$tumblr->createPost('blog.tumblr.com', array('type' => 'photo', 'source' => $photos));

from tumblr.php.

jeflopodev avatar jeflopodev commented on July 19, 2024

However... this only works for local paths right ?

The field 'photos' appear as a response field in the API Docs http://www.tumblr.com/docs/en/api/v2#photo-posts is a typo error ? Request fields are source and data... When using 'source' it works for me, I tried with this field called 'photos' but throws:

Fatal error: Uncaught Tumblr\API\RequestException: [401]: Not Authorized thrown in C:\xampp\htdocs\standalone-projects\Tumblr\Bot\vendor\tumblr\tumblr\lib\Tumblr\API\Client.php on line 434

from tumblr.php.

AbeCole avatar AbeCole commented on July 19, 2024

I havn't actually tried remote paths, I don't believe you can do multiple remote photo uploads, i.e. you need to have all the images being sent from your server to Tumblr.

I had a typo in my previous post twice due to it being copy+pasted direct from my usage environment so I had to edit a few bits after, I presume this is why you are mentioning 'photos'? It is correct to use 'source' as the script converts it to the correct format accepted by Tumblr.

from tumblr.php.

seejohnrun avatar seejohnrun commented on July 19, 2024

Here is an example of this working now with photo arrays to create photosets. Just to clear it up, source is for remote paths, data is for local paths:

<?php

require 'vendor/autoload.php';

// keys
$consumerKey = '<your>';
$consumerSecret = '<keys>';
$token = '<go>';
$tokenSecret = '<here>';

// create client
$client = new Tumblr\API\Client($consumerKey, $consumerSecret, $token, $tokenSecret);

// make blog poat
$path = '/Users/john/Desktop/wowowowowow.jpg';
$path2 = '/Users/john/Desktop/funny.jpg';
$post_detail = $client->createPost('apeyes.tumblr.com', array('type' => 'photo', 'data' => array($path, $path2)));

var_dump($post_id);

from tumblr.php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.