Reputation: 2451
I have used FHSTwitter Engine
for oauth authentication as well as to post the image and text to twitter.
When I tried to send the message alone. It posted successfully but when I send it with image
[[FHSTwitterEngine sharedEngine]postTweet:@"test with image" withImageData:imageData];
it gives the Error 204 and message : Twitter successfully processed the request, but did not return any content
If anyone has some idea to post the image with text or link.
Upvotes: 2
Views: 940
Reputation: 209
You just have to compress the image, nothing else. May be twitter api doesnt allow us to post image of big size.
NSData *data = UIImageJPEGRepresentation(imageView.image, 0.6);
now pass the data into your method. You can compress the image as per your convenience.
Upvotes: 0
Reputation: 1
NSURL *url = [NSURL URLWithString:imgURl];
NSString *strForPost=[NSString stringWithFormat:@"%@ %@",self.dynamicTextToPost.text,url];
int twitCount=[strForPost length];
int runLoop=twitCount/140;
int remender=twitCount%140;
if (runLoop==0) {
runLoop=runLoop+1;
}
if(remender!=0){
runLoop=+1;
}
dispatch_async(GCDBackgroundThread, ^{
@autoreleasepool {
// NSData *data = [[NSData alloc] initWithContentsOfURL:url];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *title = nil;
NSString *message = nil;
NSString *subStr;
NSString *strRemain=strForPost;
for (int i=0; i<=runLoop; i++) {
int j=i*140;
NSLog(@"strRemain.length==>%d",strRemain.length);
if (strRemain.length<140) {
subStr=[strRemain substringFromIndex:0];
// subStr=[strForPost substringWithRange:NSMakeRange(j, strRemain.length)];
}else if(strRemain.length>140){
subStr=[strForPost substringWithRange:NSMakeRange(j, 140)];
NSLog(@"%d",j);
NSLog(@"%d",strForPost.length);
NSLog(@"%d",strRemain.length);
NSLog(@"%d",strForPost.length-j);
NSLog(@"%d",strRemain.length-j);
strRemain=[strForPost substringWithRange:NSMakeRange(140, strRemain.length-140)];
}
NSString *strShare=[self htmlEntityDecode:subStr];
NSError *returnCode = [[FHSTwitterEngine sharedEngine]postTweet:strShare];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if (returnCode) {
title = [NSString stringWithFormat:@"Error %d",returnCode.code];
message = returnCode.domain;
} else {
title = @"Message";
message = @"Successfully Shared";
}
}
dispatch_sync(GCDMainThread, ^{
@autoreleasepool {
if ([message isEqualToString:@"Successfully Shared"]) {
}else if ([message isEqualToString:@"Twitter successfully processed the request, but did not return any content"]) {
}
else{
// unable to share
}
}
});
}
});
Upvotes: -1