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

查看:109
本文介绍了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.

我可以使用TWRequest for iOS5和MGTwitterEngine为以前的iOS版本发布状态更新,但我无法附加更新的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天全站免登陆