2

-(void)getTwittersFollowers{ ACAccountStore *store=[[ACAccountStore alloc]init]; ACAccountType *twitterAccType=[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

**[store requestAccessToAccountsWithType:twitterAccType withCompletionHandler:^(BOOL granted,NSError *error)**{
    if(!granted){
        NSLog(@"User refused to access to his account");
    }else{

        NSArray *twitterAcc=[store accountsWithAccountType:twitterAccType];

        if([twitterAcc count]>0){
            ACAccount *account=[twitterAcc objectAtIndex:0];
            NSLog(@"account name %@",[account accountDescription]);

            NSMutableDictionary *params=[[NSMutableDictionary alloc]init];
            [params setObject:@"1" forKey:@"inclue_entitles"];

            NSURL *url=[NSURL URLWithString:@"http://api.twitter.com/1/followers.json"];
            //TWRequest *request=[[TWRequest alloc]initWithURL:url parameters:params requestMethod:TWRequestMethodGET];
            SLRequest *request=[SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:params];
            [request setAccount:account];
            [request performRequestWithHandler:^(NSData *responce,NSHTTPURLResponse *urlResponce,NSError *error){
                if(!responce){
                    NSLog(@"%@",error);
                }else{
                    NSError *jsonError;
                    NSMutableDictionary *followers=[NSJSONSerialization JSONObjectWithData:responce options:NSJSONReadingMutableLeaves error:&error];

                        if(followers!=nil){
                            for (int i=0; i<[[followers objectForKey:@"users"] count]; i++) {
                                NSLog(@"_____%@",[[[followers objectForKey:@"users"] objectAtIndex:i] objectForKey:@"screen_name"]);
                                NSLog(@"______________________________________%@",[[[followers objectForKey:@"users"] objectAtIndex:i] objectForKey:@"profile_image_url"]);


                                [nameArray addObject:[[[followers objectForKey:@"users"] objectAtIndex:i] objectForKey:@"screen_name"]];


                                NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[[followers objectForKey:@"users"] objectAtIndex:i] objectForKey:@"profile_image_url"]]];


                                [imageArray addObject:imageData];

                                NSLog(@"%i", [imageArray count]);
                            }

                        }else{
                            NSLog(@"%@",jsonError);
                        }


                }
            }];
        }
    }


}];

}

what should i use instead of highlighted code...?

Nitesh
  • 1,924
  • 21
  • 31

1 Answers1

8

Though it's for some reason not explicitly mentioned in the documentation, the replacement for the method is - (void)requestAccessToAccountsWithType:(ACAccountType *)accountType options:(NSDictionary *)options completion:(ACAccountStoreRequestAccessCompletionHandler)completion (which can easily be found out by looking at the documentation)

JustSid
  • 25,168
  • 7
  • 79
  • 97
  • [self getTwittersFollowers]; FollowersViewController *friends = [[FollowersViewController alloc]initWithStyle:UITableViewStylePlain]; friends.nameArray = self.nameArray; friends.imageArray = self.imageArray; UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:friends]; [self presentViewController:navigationController animated:YES completion:nil]; – Nitesh Sep 02 '13 at 12:37
  • Thanks for answer. i have one more question that i have called this method on button click action, just as compiler calls this method, it goes to its block and suddenly without completing it, it switches back to button action's further instructions and popped next view controller as i coded which will be having data retrieved by this block. i got empty table view there. but i see compiler is running that block now.again coming back by navigation's back btn just as i clicked this button now it will show me twitter's followers list. – Nitesh Sep 02 '13 at 12:37
  • @Nitesh The method is asynchronous. The block isn't guaranteed to be called before the method returns. – JustSid Sep 02 '13 at 13:12
  • yeah i observed this in execution. but i put MBProgressHUD for hanging it so that it would hang here till this block completes.i wonder why even this is not working here..? – Nitesh Sep 02 '13 at 13:37
  • what should be passed for `options`? – user102008 Jan 21 '14 at 04:00
  • @user102008 That depends on the kind of account you are requesting. The documentation holds more information – JustSid Jan 23 '14 at 20:09
  • @user102008 "Certain account types (such as Facebook) require an options dictionary. This method will throw an NSInvalidArgumentException if the options dictionary is not provided for such account types. Conversely, if the account type does not require an options dictionary, the options parameter must be `nil`" Twitter doesn't require options btw – Cbas Mar 25 '16 at 00:58