Как «подписаться» на людей с новым Twitter API в iOS 5? - PullRequest
1 голос
/ 10 ноября 2011

Возможно ли "следить" за людьми в Твиттере, используя новый API Twitter в iOS 5?

Если да, то как?Кажется, я не могу понять, куда идти.

Может кто-нибудь опубликовать пример, используя TWRequest, пожалуйста?Спасибо.

Ответы [ 2 ]

6 голосов
/ 21 января 2013

Добавьте платформы Твиттера и Аккаунтов и используйте следующий метод:

- (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];
                        });
                    }
                }];
            }
        }
    }];
}
2 голосов
/ 10 ноября 2011

Вы можете сделать это, используя существующий Twitter API .

Вот блог, описывающий все детали (статья 2 в серии 2): http://iosdevelopertips.com/core-services/ios-5-twitter-framework-part-2.html

...