iOS 5 使用 Twitter API 将照片附加到 Twitter [英] iOS 5 Attach photo to Twitter with Twitter API

查看:17
本文介绍了iOS 5 使用 Twitter API 将照片附加到 Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使用 TWRequest 或类似方法将照片添加到 Twitter 时间线?在这种情况下,我非常非常迷茫.

Is there any way to add a photo to Twitter timeline using TWRequest or anything like so?? I'm very very lost in this case.

我可以使用适用于 iOS5 的 TWRequest 和适用于之前 iOS 版本的 MGTwitterEngine 发布状态更新,但我无法将 UIImage 附加到更新中.

I can post a status update using TWRequest for iOS5 and MGTwitterEngine for previous iOS version, but I'm not able to attach a UIImage to the update.

预先感谢您提供的任何帮助.

Thanks in advance for any help provided.

推荐答案

我在这个网站上找到并使用了很多很棒的答案,谢谢大家,认为是时候回馈了 :) 详细说明诺亚的答案,这是最终代码对我有用,可以使用 TWRequest 在推文上获取图像和文本...

I have found and used so many great answers on this site, Thanks everyone, thought it's about time to give back :) Elaborating on Noah's answer, this is the final code that worked for me to get an image and text on a tweet using TWRequest...

            TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:nil requestMethod:TWRequestMethodPOST];

            UIImage * image = [UIImage imageNamed:@"myImage.png"];

            //add text
            [postRequest addMultiPartData:[@"I just found the secret level!" dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data"];
            //add image
            [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/form-data"];

            // Set the account used to post the tweet.
            [postRequest setAccount:twitterAccount];

            // Perform the request created above and create a handler block to handle the response.
            [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                [self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];
            }];

我发现使用 TWRequest 是我的场景的最佳解决方案,因为我不希望用户能够在发推之前编辑帖子(这是使用 TWTweetComposeViewController 的问题)

I found using TWRequest to be best solution for my scenario as I didn't want the user to be able to edit the post before tweeting (which was the issue with using TWTweetComposeViewController)

这篇关于iOS 5 使用 Twitter API 将照片附加到 Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆