xcode 如何在 ios5 中从我的 iphone 在 twitter 上发送图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8336739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I send image on twitter from my iphone in ios5
提问by iPhone
I want to share image on twitter from my iphone using twitter api twitter+OAuth but I don't know how to share it from my iphone. I have tried same operation using sharekit but I did not get success. Would you tell me how to share image on twitter from iphone using twitter api?
我想使用 twitter api twitter+OAuth 从我的 iphone 在 twitter 上共享图像,但我不知道如何从我的 iphone 共享它。我使用 sharekit 尝试过相同的操作,但没有成功。你能告诉我如何使用 twitter api 从 iphone 在 twitter 上分享图像吗?
回答by iPhone
The link provided by zot works but I have to add some code plus I have to add two frameworks Twitter.framework and Account.framework. The modified code is as below
zot 提供的链接有效,但我必须添加一些代码,而且我必须添加两个框架 Twitter.framework 和 Account.framework。修改后的代码如下
- (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];
}];
}
}
}];
}
回答by zot
did you check this out: iOS 5 Attach photo to Twitter with Twitter API
您是否检查过:iOS 5 使用 Twitter API 将照片附加到 Twitter
This only works for phones with iOS5.
这仅适用于装有 iOS5 的手机。
In my app, which was pre-iOS5, I used TwitPic to upload the photo and post the Twitter status. There's a nice tutorial on how to use ASHttpRequest to do the Twitter Status update here:
在 iOS5 之前的应用程序中,我使用 TwitPic 上传照片并发布 Twitter 状态。这里有一个关于如何使用 ASHttpRequest 进行 Twitter 状态更新的不错的教程:
http://www.icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/
http://www.icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/
if you want to pursue this method let me know as there is additional work that you need to do to beyond this tutorial and you'll need to get an API key from TwitPic as well.
如果您想采用这种方法,请告诉我,因为除了本教程之外,您还需要做其他工作,而且您还需要从 TwitPic 获取 API 密钥。
回答by Wolverine
Use Sharekit For Sharing Images.
使用 Sharekit 共享图像。
tutorial: How to Add Twitter Sharing to Your iPhone/iPad App Using ShareKit