I'm able to successfully submit text posts (with 201 responses) but when I change my type parameter to "video" and add appropriate embed and caption parameters, I get a 500 response from Tubmlr.
Their documentation is pretty light on the details of what I need to give for an embed value, but I've tried linking directly to the file, <iframe>, <embed>, with URL escaping using both methods at the W3Schools, and I always get a 500 response.
From what I've seen on other message boards, this is not uncommon, but no one has an answer. The code I'm using is below.
NSString *apiCallURL = [NSString stringWithFormat:@"http://api.tumblr.com/v2/blog/%@/post", self.baseURL];
NSLog(@"API Call URL: %@", apiCallURL);
NSURL *url = [NSURL URLWithString:apiCallURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"utf-8" forHTTPHeaderField:@"charset开发者_如何学编程"];
NSMutableString *body = [[NSMutableString alloc] init]; //Using NSMutableString instead of stringWithFormat to avoid problems with % encoding
[body appendFormat:@"type=video&caption=%@", caption];
[body appendString:@"&embed=EMBED CODE HERE"];
[request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];
[body release], body = nil;
[self.authentication authorizeRequest:request];
NSError *error = nil;
NSHTTPURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (error)
{
NSLog(@"Error! \n%@", error);
return;
}
if (data) {
// API fetch succeeded
NSString *str = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"Sharing response (%d): %@", [response statusCode], str);
}
The output I get is
Sharing response (500):
The embed code I've been trying to use works through tumblr's web interface and is the URL encoded version of the following:
<embed width="480" height="360" src="http://www.keek.com/embed/decaaab" frameborder="0" allowfullscreen />
You'll likely see an answer from the Tumblr devs on the mailing list here:
https://groups.google.com/forum/#!topic/tumblr-api/id_pKWwPcro
It seems to be a problem on tumblr's end.
精彩评论