使用结构获取来自twitter sdk的关注者列表,但不能超过20个。另一个限制是首先获取所有关注者,然后上传到api。我使用下面的代码来获取关注者列表。请指导您需要在现有代码中进行更改或需要转换为某种新方式。
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if (granted) {
//[MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
// Check if the users has setup at least one Twitter account
if (accounts.count > 0)
{
ACAccount *twitterAccount = [accounts objectAtIndex:0];
// Creating a request to get the info about a user on Twitter
SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/followers/list.json"] parameters:[NSDictionary dictionaryWithObject:twitterAccount.username forKey:@"screen_name"]];
[twitterInfoRequest setAccount:twitterAccount];
// Making the request
[twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
// Check if we reached the reate limit
if ([urlResponse statusCode] == 429) {
NSLog(@"Rate limit reached");
return;
}
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
}
// Check if there is some response data
if (responseData) {
NSError *error = nil;
NSArray *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
// Filter the preferred data
NSArray *arrFollowList = [TWData valueForKey:@"users"];
// Filter the preferred data
NSMutableArray *arrFollowersList = [[NSMutableArray alloc]init];
for(int i =0; i<[arrFollowList count]; i++)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:[[arrFollowList objectAtIndex:i] valueForKey:@"name"] forKey:@"FriendName"];
[dict setObject:@"" forKey:@"Email"];
[dict setObject:strType forKey:@"FriendType"];
[dict setObject:[[arrFollowList objectAtIndex:i] valueForKey:@"id"] forKey:@"UserAccountId"];
//[dict setObject:@"" forKey:@"UserAccountId"];
[dict setObject:@"1" forKey:@"Team_Id"];
[dict setObject:[[arrFollowList objectAtIndex:i] valueForKey:@"profile_image_url"] forKey:@"ProfileImage"];
[arrFollowersList addObject:dict];
}
NSString *teamId = @"1";
NSDictionary *objDict = [NSDictionary dictionaryWithObjectsAndKeys:
teamId, @"Team_Id",
arrFollowersList, @"userFriendList",
nil];
NSLog(@"dict %@",objDict);
[iOSRequest postData:[NSString stringWithFormat:@"%@", kFriendListUpdateUrl] :objDict :^(NSDictionary *response_success)
{
NSLog(@"response_success:%@", response_success);
if([[response_success valueForKey:@"message"] isEqualToString:@"Success"])
{
NSMutableDictionary *dictSquads = [[NSMutableDictionary alloc]init];
[dictSquads setObject:[standardDefaults valueForKey:@"UserId"] forKey:@"User_Id"];
[dictSquads setObject:@"1" forKey:@"Team_Id"];
[dictSquads setObject:strType forKey:@"FriendType"];
}
}
:^(NSError *response_error)
{
}];
}
});
}];
}
} else {
NSLog(@"No access granted");
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}
}];