I'm trying to Fetch User's friends List. my last working Code that i implement in FacebookSDK 3.12 is now of No use because facbook have changed all their classes and even deleted old Classes, below is my old Code:
#pragma mark - Facebook Methods -
-(void)initiateFacebookSessionIfNot
{
if (FBSession.activeSession.isOpen)
{
[self getUserFriendsIds];
} else
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_birthday",@"friends_hometown",
@"friends_birthday",@"friends_location",
nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status,NSError *error)
{
if (error) {
NSString *alertMessage, *alertTitle;
if (error.fberrorShouldNotifyUser) {
alertTitle = @"Something Went Wrong";
alertMessage = error.fberrorUserMessage;
} else if (error.fberrorCategory == FBErrorCategoryUserCancelled) {
NSLog(@"user cancelled login");
} else {
// For simplicity, this sample treats other errors blindly.
alertTitle = @"Unknown Error";
alertMessage = @"Error. Please try again later.";
NSLog(@"Unexpected error:%@", error);
}
if (alertMessage)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertTitle
message:error.fberrorUserMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
[self getUserFriendsIds];
}
}];
}
}
-(void)getUserFriendsIds
{
FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,username"];
[ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSMutableArray *fbFriendIDs;
NSMutableArray *fbFriendsName;
NSMutableArray *fbFriendsUserName;
NSMutableArray *data = [[NSMutableArray alloc]initWithArray:[result objectForKey:@"data"]];
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (!(NSDictionary*)obj[@"username"]) {
NSDictionary *newDictionary =@{@"id": (NSDictionary*)obj[@"id"],
@"name": (NSDictionary*)obj[@"name"],
@"username": @"0"
};
[data replaceObjectAtIndex:idx withObject:newDictionary];
}
}];
fbFriendsUserName = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.username"]];
fbFriendsName = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.name"]];
fbFriendIDs = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.id"]];
NSDictionary *queryDictionary =
@{@"user_id": userObj.user_id,
@"friend_ids":[fbFriendIDs componentsJoinedByString:@","],
@"names":[fbFriendsName componentsJoinedByString:@","],
@"usernames":[fbFriendsUserName componentsJoinedByString:@","]
};
[[RequestHandler sharedClient] CheckFBFriendsWithDictionary:queryDictionary WithCompletionBlock:^(NSArray *TUNFriendsArray, NSArray *FBFriendsArray, NSString *errorMessage) {
if (!errorMessage) {
tunFriendsArray = [[NSMutableArray alloc]initWithArray:TUNFriendsArray];
// fbFriendsArray = [[NSMutableArray alloc]initWithArray:FBFriendsArray];
[_facebookTableView reloadData];
}
else{
[ApplicationUtilities ShowAlertViewWithTitle:APP_NAME Message:errorMessage];
}
}];
}];
[SVProgressHUD dismiss];
}
Aucun commentaire:
Enregistrer un commentaire