首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在ios5模式下用iphone在twitter上发送图片

如何在ios5模式下用iphone在twitter上发送图片
EN

Stack Overflow用户
提问于 2011-12-01 12:58:46
回答 3查看 5.3K关注 0票数 3

我想在我的iphone上使用twitter api twitter+OAuth在twitter上分享图片,但是我不知道如何在iphone上分享。我也尝试过使用sharekit执行相同的操作,但没有成功。你能告诉我如何使用twitter api在iphone上分享图片吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-12-02 14:39:11

zot提供的链接可以工作,但我必须添加一些代码,另外我还必须添加两个框架Twitter.framework和Account.framework。修改后的代码如下

代码语言:javascript
运行
复制
- (IBAction)sendCustomTweet:(id)sender {
    // Create an account store object.
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    // Create an account type that ensures Twitter accounts are retrieved.
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    // Request access from the user to use their Twitter accounts.
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
        if(granted) {
            // Get the list of Twitter accounts.
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];


            if ([accountsArray count] > 0) {
                // Grab the initial Twitter account to tweet from.
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];


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


                TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] 
                                                             parameters:[NSDictionary dictionaryWithObject:@"Hello. This is a tweet." forKey:@"status"] requestMethod:TWRequestMethodPOST];

                   // "http://api.twitter.com/1/statuses/update.json" 

                [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];


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

                [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];
                }];
            }
        }
    }];
}
票数 5
EN

Stack Overflow用户

发布于 2011-12-02 04:45:07

你看过这个了吗:iOS 5 Attach photo to Twitter with Twitter API

这只适用于安装了iOS5的手机。

在我的iOS5之前的应用程序中,我使用TwitPic上传照片并发布推特状态。这里有一个关于如何使用ASHttpRequest进行推特状态更新的很好的教程:

http://www.icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/

如果您想使用此方法,请告诉我,因为除了本教程之外,您还需要做其他工作,您还需要从TwitPic获取一个API。

票数 1
EN

Stack Overflow用户

发布于 2011-12-01 13:05:11

使用Sharekit共享图像。

教程:How to Add Twitter Sharing to Your iPhone/iPad App Using ShareKit

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8336739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档