Reputation: 4170
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?
Upvotes: 3
Views: 5266
Reputation: 4170
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
- (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];
}];
}
}
}];
}
Upvotes: 5
Reputation: 131
did you check this out: iOS 5 Attach photo to Twitter with Twitter API
This only works for phones with 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:
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.
Upvotes: 1
Reputation: 4329
Use Sharekit For Sharing Images.
tutorial: How to Add Twitter Sharing to Your iPhone/iPad App Using ShareKit
Upvotes: 0