0
我想從Facebook獲取'Facebook朋友'列表,其中可能有超過500個朋友,因此Facebook會爲結果分頁。這是方法。iOS:使用分頁獲取Facebook朋友
- (void)getFaceBookFriends
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/friends" parameters:@{@"fields" : @"first_name, last_name,email,name,gender,id,picture"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"%@",result);
NSArray *arrData = [result valueForKey:@"data"];
for (NSDictionary *dictItem in arrData) {
[array addObject:dictItem];
}
[tableView reloadData];
}
else
{
}
}];
}
else
[self checkFacebookSetup];
}
- (void)checkFacebookSetup
{
[self startLoadingActivity];
self.loginButton.publishPermissions = @[@"basic_info", @"email", @"user_friends"];
self.loginButton.delegate =self;
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
loginManager.loginBehavior = FBSDKLoginBehaviorSystemAccount;
/*Editted*/
[loginManager logInWithReadPermissions:@[@"email"] fromViewController:(UIViewController *)self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Access denied", nil) message:NSLocalizedString(@"You are not given access to your profile. enable it in settings", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil, nil];
[alert show];
[self stopLoadingActivity];
} else if (result.isCancelled) {
// Handle cancellations
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Access denied", nil) message:NSLocalizedString(@"You are not given access to your profile. enable it in settings", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil, nil];
[alert show];
[self stopLoadingActivity];
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if ([result.grantedPermissions containsObject:@"email"])
{
// Do work
if ([FBSDKAccessToken currentAccessToken])
{
[self getFaceBookFriends];
}
}
}
}];
}