通过FHSTwitterEngine发布图片

时间:2013-09-17 08:58:48

标签: ios objective-c fhs-twitter-engine

我已将FHSTwitter Engine用于oauth身份验证,并将图片和文字发布到Twitter。

当我尝试单独发送消息时。它发布成功,但当我发送图像

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

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

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

2 个答案:

答案 0 :(得分:0)

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

ListView

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

答案 1 :(得分:-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
                    }
                }
            });
        }
    });