I am new to ios application development. I want to learn the integration with facebook in ios and choose a list of friends.
I follow the git hub code https://github.com/facebook/facebook-ios-sdk/tree/master/samples/FriendPickerSample
and follow all the steps for this. my code is:
- (IBAction)friendPicker:(id)sender {
if (!FBSession.activeSession.isOpen)
{
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if(error)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
else if (session.isOpen)
{
[self friendPicker:sender];
}
}];
return;
}
if(FBSession.activeSession.isOpen)
{
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
if(error)
{
NSLog(@"error : %@",error);
}
else
{
NSArray* friends = [result objectForKey:@"data"];
NSLog(@"total array : %@",result);
NSLog(@"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
}
}
}];
}
if(self.friendPickerController == nil)
{
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = @"Pick Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
[self presentViewController:self.friendPickerController animated:YES completion:nil];
}
-(void)fillTextAndDismiss:(NSString * )text
{
[self.selectedFrdView setText:text];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)facebookViewControllerDoneWasPressed:(id)sender
{
NSMutableString *text = [[NSMutableString alloc] init];
for(id<FBGraphUser> user in self.friendPickerController.selection)
{
if([text length])
{
[text appendString:@", "];
}
[text appendString:user.name];
}
[self fillTextAndDismiss:text.length >0 ? text : @"<none>"];
}
-(void)facebookViewControllerCancelWasPressed:(id)sender
{
[self fillTextAndDismiss:@"<cancelled>"];
}
I also create facebookAppId and the plist file is also updated with this key. then I also get this error:
2014-05-12 14:21:27.043 fbFrndTest[2753:90b] error : Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xb166450 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) Unknown fields: username.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:ErrorSessionKey=<FBSession: 0xb521fd0, state: FBSessionStateOpen, loginHandler: 0x0, appID: 1481684055397512, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xb523240>, expirationDate: 2014-07-11 05:48:12 +0000, refreshDate: 2014-05-12 07:26:43 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
)>}
GitHUB code worked successfully, but my code gives an error.
source
share