简体   繁体   English

如何通过iOS 5中的新Twitter API“关注”人们?

[英]How to “follow” people with the new Twitter API in iOS 5?

Is it possible "follow" people on Twitter using the new Twitter API in iOS 5? 是否可以在iOS 5中使用新的Twitter API在Twitter上“关注”人们?

If so, how? 如果是这样,怎么办? I can't seem to figure out which way to go here. 我似乎不知道该走哪条路。

Can someone post an example using TWRequest please? 有人可以使用TWRequest发布示例吗? Thanks. 谢谢。

Add Twitter and Accounts frameworks, and use the following method: 添加Twitter和Accounts框架,并使用以下方法:

- (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];
                        });
                    }
                }];
            }
        }
    }];
}

You can do it using the existing Twitter API . 您可以使用现有的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 这是描述所有详细信息的博客文章(共2个系列,第2条): http : //iosdevelopertips.com/core-services/ios-5-twitter-framework-part-2.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM