Reputation: 14835
Is it possible "follow" people on Twitter using the new Twitter API in iOS 5?
If so, how? I can't seem to figure out which way to go here.
Can someone post an example using TWRequest
please? Thanks.
Upvotes: 1
Views: 3524
Reputation: 1243
You can do it using the existing Twitter API.
Here is a blogpost describing all the details ( article 2 in a series of 2 ): http://iosdevelopertips.com/core-services/ios-5-twitter-framework-part-2.html
Upvotes: 2
Reputation: 4122
Add Twitter and Accounts frameworks, and use the following method:
- (IBAction)tweet_action
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:@"numerologistiOS" forKey:@"screen_name"];
[tempDict setValue:@"true" forKey:@"follow"];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/1/friendships/create.json"]
parameters:tempDict
requestMethod:TWRequestMethodPOST];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
NSLog(@"%@", output);
if (urlResponse.statusCode == 200)
{
UIAlertView *statusOK = [[UIAlertView alloc]
initWithTitle:@"Thank you for Following!"
message:@"You are now following us on Twitter!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[statusOK show];
});
}
}];
}
}
}];
}
Upvotes: 6