Lucè Brùlè Lucè Brùlè - 1 year ago 121
iOS Question

Twitter - Follow Button

I'm currently developing on an iOS app, which catches some tweets from the streaming api. For that reason I take the username and password of an user to authenticate. In addition to this I want to give the user the opportunity to follow some people on twitter. I created an UIButton and now want to call a url or something like this to follow a specific user. Is this possible?

Answer Source

If you are using iOS 6 to follow user on twitter:

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(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:@"twitter_name" forKey:@"screen_name"];
        [tempDict setValue:@"true" forKey:@"follow"];
        NSLog(@"*******tempDict %@*******",tempDict);


        SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@""] parameters:tempDict];
        [postRequest setAccount:twitterAccount];
        [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
            NSString *output = [NSString stringWithFormat:@"HTTP response status: %i Error %d", [urlResponse statusCode],error.code];
            NSLog(@"%@error %@", output,error.description);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download