Getting error while posting image using FHSTwitterEngine

那年仲夏 提交于 2019-12-30 14:57:19

问题


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


回答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.




回答2:


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




回答3:


compress the existing image using this code...

NSData *data = UIImageJPEGRepresentation(imageView.image, 0.6);



回答4:


You need post the string length below then 130 characters



来源:https://stackoverflow.com/questions/19096713/getting-error-while-posting-image-using-fhstwitterengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!