0

In my app i integrated FHSTwitterEngine for posting images in twitter. Till last week it is working fine. But all of a sudden, while trying to post an image it is showing 204 Error

Domain=FHSErrorDomain Code=204 "The request did not return any content."

i don't think that it is an issue with duplicate post, because image will change according to user selection and while trying to post image first time itself it is giving the error.

Text based tweets are working properly. problem is with image posting only

code i am using

dispatch_async(GCDBackgroundThread, ^{
    @autoreleasepool {

        NSError *returnCode = [[FHSTwitterEngine sharedEngine]postTweet:self.textToTweet withImageData:UIImagePNGRepresentation(tweetImg)];

        NSString *title = nil;
        NSString *message = nil;

        if (returnCode) {
            NSLog("Error-->%d",returnCode.code);               
        } else {
            title = @"Tweet Posted";
            message = @"Successfully";
        }
     }
});

Thanks in advance

kumar
  • 151
  • 1
  • 12

4 Answers4

1

It's a malformed multipart form data problem.

Take a look at FHSTwitterEngine.m.

Look for these lines

- (NSError *)sendPOSTRequestForURL:(NSURL *)url andParams:(NSDictionary *)params
...
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n",key] dataUsingEncoding:NSUTF8StringEncoding]];        
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:data];

Add these lines below it

if ([obj isKindOfClass:[NSData class]]) {
    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
}

I also noticed that it has missing status params bug.
Look for

- (NSError *)postTweet:(NSString *)tweetString withImageData:(NSData *)theData inReplyTo:(NSString *)irt {
...
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"media[]"] = theData;

And add this

params[@"status"] = tweetString;

Or you could get the fixes here: https://github.com/alvani/FHSTwitterEngine/blob/master/FHSTwitterEngine/FHSTwitterEngine.m

Thanks.

alpha2
  • 277
  • 3
  • 5
  • Thank you @alpha2. Posting image issue has been resolved but now when ever i am trying to post the same image again and again it is simply posting the image instead of showing duplicate post error and also some time it is giving -1001 error code – kumar Oct 04 '13 at 03:51
  • hello @alpha2 I am using this updated code for posting string to twitter but I am getting the same error **Domain=FHSErrorDomain Code=204 "The request did not return any content."** – Sumeet Mourya Feb 06 '14 at 06:48
  • Hi @alpha2, What is obj in [**obj** isKindOfClass:[NSData class]]? – arunit21 Sep 20 '14 at 05:02
  • @arunit21 It's an id type containing NSString or NSData that will be used as http multipart field – alpha2 Sep 22 '14 at 05:20
0

I was not be able to post image on Twitter, But Using this code now i am able to post the data with image to twitter.

https://github.com/alvani/FHSTwitterEngine

Simply replace your FHSTwitterEngine with this library.

its simply added some Changes or bugs in the Library

Gaurav Singla
  • 2,271
  • 26
  • 43
0

compress the existing image using this code...

NSData *data = UIImageJPEGRepresentation(imageView.image, 0.6);
Smit Shah
  • 209
  • 2
  • 9
0

You need post the string length below then 130 characters

Di B.
  • 1,009
  • 10
  • 11