我試圖讓Facebook好友列表,並在自定義視圖,如「foresqure應用程序」顯示它獲取Facebook好友列表並將其顯示在自定義視圖中?
我是什麼意思「四方」要求的許可,並在應用程式內牆上張貼無需離開應用程序到瀏覽器或Facebook的應用程序?之後,該應用程序獲取所有朋友並將其顯示在自定義tableView中。
這裏是我的嘗試:
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"]
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
} else if (session.isOpen) {
//[self pickFriendsButtonClick:sender];
NSLog(@"aaaa");
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:@"data"];
NSLog(@"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
}
}];
}
}];
}
在這種情況下,它會打開Safari索要permision不是應用程序和朋友陣列內允許nill或數= 0
檢查我的答案。 –
@DarshanKunjadiya在我的mac中檢查這個http://www.filedropper.com/testface – Omarj
這段代碼是完美的。我只更改我的Facebook應用程序ID並獲取所有朋友列表。 –