问题
I am able to upload one picture but I can't create a photoset with multiple images using API.
Documentation says: Paramater: Array (URL-encoded binary contents)
One or more image files (submit multiple times to create a slide show)
Does anyone know how to do it?
回答1:
It's kind of a painful process, but I figured it out after studying the python code Tumblr posted. In short, it requires getting the hexadecimal for the photo and then doing some substitutions.
I've created a simple iOS / iPad / iPhone project on GitHub that uploads multiple photos to photosets using the Tumblr API, based heavily on the ASIHTTPRequest+OAuth project. It works so far in my limited testing -- feel free to make use of it and let me know how it goes.
回答2:
The new PhotoUpLink for iPhone uploads true Tumblr photosets. It is a free download from the App Store at http://uplink.to/5o example photosets at http://photouplink.tumblr.com
The Tumblr uploader is based on @VictorVanHee's epic. I did optimize the code by switching to straight C for the NSData stringWithoutURLEncoding subroutine:
- (NSString *) stringWithoutURLEncoding
{
NSString *hexDataDesc = [self description];
hexDataDesc = [[hexDataDesc stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];
int hlen = [hexDataDesc length];
NSString *hexDataDescU = [hexDataDesc uppercaseString];
const char *hexcString = [hexDataDescU cStringUsingEncoding:NSASCIIStringEncoding];
char *newStringC = malloc(hlen *3);
memset(newStringC, 0, hlen *3);
int xC= 0, upd = 3000, value = 0;
char *componentC = malloc(5); // = "XX";
componentC[2] = 0;
const char *px = "%x"; char ptc = '%';
for (int x=0; x<hlen; x+=2)
{
componentC[0] = hexcString[x];
componentC[1] = hexcString[x+1];
value = 0;
sscanf(componentC, px, &value);
if ((value <=46 && value >= 45) || (value <=57 && value >= 48) || (value <=90 && value >= 65) || (value == 95) || (value <=122 && value >= 97)) //48-57, 65-90, 97-122
{
newStringC[xC++] = (char)value;
}
else
{
newStringC[xC++] = ptc;
newStringC[xC++] = (char)componentC[0];
newStringC[xC++] = (char)componentC[1];
}
}
NSString *newString = [NSString stringWithCString:newStringC encoding:NSASCIIStringEncoding];
NSString *aNewString = [newString stringByReplacingOccurrencesOfString:@"%20" withString:@"+"];
free (newStringC);
free (componentC);
return aNewString;
}
回答3:
I was having trouble with this too. Here is a gist in python of what ended up working for me: https://gist.github.com/charlesbrandt/11eadaec114288d621fa
The trick is that all photos must be added to your post parameters with 'data[#]' for keys. ('data[0]', 'data[1]', etc)
回答4:
It's super simple, use 'source' parameter if you have only one image to upload, if there are multiple images, switch the parameter to 'data' and initialize it with the array of image URLs. For php tumblr client, following snippet can be used:
$paramsToPost = [
'type' => 'photo',
'tags' => 'tag1, tag2, tag2',
'caption' => 'caption for photo(s)',
'link' => 'http://example.com/click-through-url'
];
if (is_array($imageData)) {
$paramsToPost['data'] = $imageData;
} else {
$paramsToPost['source'] = $imageData;
}
$client = new Tumblr\API\Client($consumerKey, $consumerSecret);
$client->setToken($token, $tokenSecret);
$response = $client->createPost($blogName, $paramsToPost);
来源:https://stackoverflow.com/questions/6878662/tumblr-api-how-to-upload-multiple-images-to-a-photoset