2

我已用于FHSTwitter Engineoauth 身份验证以及将图像和文本发布到 Twitter。

当我试图单独发送消息时。它发布成功但是当我用图片发送它时

[[FHSTwitterEngine sharedEngine]postTweet:@"test with image" withImageData:imageData];

它给出了错误 204 和消息:Twitter 成功处理了请求,但没有返回任何内容

如果有人有想法发布带有文本或链接的图像。

4

2 回答 2

0

你只需要压缩图像,没有别的。可能是 twitter api 不允许我们发布大尺寸的图像。

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

现在将数据传递到您的方法中。您可以根据自己的方便压缩图像。

于 2015-05-30T12:25:43.753 回答
-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
                    }
                }
            });
        }
    });
于 2014-05-01T11:34:26.573 回答