3

I want to send the friend request from my app. I used following code

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My Title", @"title",
                                   @"Come check out my app.",  @"message",
                                   FrienduserId, @"id",
                                   nil];
[FBWebDialogs 
 presentDialogModallyWithSession:nil 
 dialog:@"friends" 
 parameters:[params mutableCopy] 
 handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error){
    if (error) {
        NSLog(@"%@",error);
    }
    else
    {
        NSLog(@"done");
    }
 }];

and It displays dialog, when i click on confirm it will gives message Sorry something went wrong . We are working on getting this fixed as soon as we can.

I have integrated Facebook SDK successfully. I got my profile information and also my friends list. So Please help me to solve this.

vokilam
  • 10,153
  • 3
  • 45
  • 56
Raj
  • 637
  • 13
  • 32
  • If I understand https://developers.facebook.com/docs/reference/dialogs/requests/ correctly, you have to be a native iOS App (set so in the corresponding Facebook App) to send this request - is you app setup so? – Blitz Feb 12 '14 at 16:36
  • Also, did you check what happens when you leave out the params? – Blitz Feb 12 '14 at 16:36
  • Hi, you are not sending friend request here. you just sharing or posting in Friend's Wall here. – Muruganandham K Feb 13 '14 at 07:31
  • possible duplicate of [How to invite friends to my application via facebook iOS SDK and Graph API](http://stackoverflow.com/questions/10834140/how-to-invite-friends-to-my-application-via-facebook-ios-sdk-and-graph-api) – Almo Aug 25 '14 at 20:59

3 Answers3

2
NSLog(@"%@",[app.Arr_Facebook_Frnd objectAtIndex:indexpath]);

NSString *str_id;
NSString *str_name;
NSString *str_link;

    str_id = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:@"id"];
    str_name = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:@"name"];
    str_link = @"www.google.com";


NSDictionary *params = @{
                         @"name" : str_name,
                         @"caption" : @"",
                         @"description" : @"",
                         @"picture" : @"",
                         @"link" : str_link,
                         @"to":str_id,
                         };

// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
                                       parameters:params
                                          handler:
 ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
     if (error) {
         NSLog(@"Error publishing story.");
         [self.indicator stopAnimating];
     } else {
         if (result == FBWebDialogResultDialogNotCompleted) {
             NSLog(@"User canceled story publishing.");
             [self.indicator stopAnimating];
         } else {
             NSLog(@"Story published.");
             [self.indicator stopAnimating];
         }
     }}];
Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
  • if solve your problem then accept my answer please.,, – Bhavesh Nayi Feb 14 '14 at 04:58
  • but your code is for post message on FB wall I dont want this , I want to send friend request to any other people who is on FB, say I have your FB id then through my app I am able to send FB friend request to you. – Raj Feb 14 '14 at 05:10
  • you are not sending friend request here. you just sharing or posting in Friend's Wall here. – Bhavesh Nayi Feb 14 '14 at 05:19
1

replace this

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My Title", @"title",
                                   @"Come check out my app.",  @"message",
                                   FrienduserId, @"to",
                                   nil];

EDIT:
change the method for calling

[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^()];

and refer here

Community
  • 1
  • 1
Muruganandham K
  • 5,271
  • 5
  • 34
  • 62
  • Hey your code is for post message on FB wall I dont want this , I want to send friend request to any other people who is on FB, say I have your FB id then through my app I am able to send FB friend request to you. – Raj Feb 14 '14 at 05:14
  • your code result saying you can not post to users wall :( – Raj Feb 14 '14 at 05:14
  • i think sending Friend request to any one is not possible unless you having their `id`. – Muruganandham K Feb 14 '14 at 05:22
1

check this code.

/* * Event: Done button clicked */

- (void)facebookViewControllerDoneWasPressed:(id)sender {
    FBFriendPickerViewController *friendPickerController =
    (FBFriendPickerViewController*)sender;
    NSLog(@"Selected friends: %@", friendPickerController.selection);
   // Dismiss the friend picker
[[sender presentingViewController] dismissViewControllerAnimated:YES completion:^{

    NSMutableString *text=[[NSMutableString alloc] init];
    for (id<FBGraphUser> user in friendPickerController.selection) {
        if ([text length]) {
            [text appendString:@", "];
        }
        [text appendFormat:@"%@",user.id];
    }
    [self friendSelectionDone:text.length > 0 ? text : @"<None>"];
}];
}

/* * Event: Cancel button clicked */

- (void)facebookViewControllerCancelWasPressed:(id)sender {
    NSLog(@"Canceled");
   // Dismiss the friend picker
   [[sender presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark
-(void)friendSelectionDone:(NSString*)userId{

if ([userId length]<1) {

    return;
}

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Check this app out...",  @"message",
                               userId, @"to",
                               nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
                                              message:[NSString stringWithFormat:@"Come and check out the App"]
                                                title:nil
                                           parameters:params
                                              handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                  if (error) {
                                                      // Case A: Error launching the dialog or sending request.
                                                      NSLog(@"Error sending request.");
                                                  } else {
                                                      if (result == FBWebDialogResultDialogNotCompleted) {
                                                          // Case B: User clicked the "x" icon
                                                          NSLog(@"User canceled request.");
                                                      } else {
                                                          NSLog(@"Request Sent.");

                                                          UIAlertView *alert=[[UIAlertView alloc] initWithTitle:APP_NAME
                                                                                                        message:@"Request Sent to your friends"
                                                                                                       delegate:nil
                                                                                              cancelButtonTitle:@"OK"
                                                                                              otherButtonTitles:nil, nil];
                                                          [alert show];
                                                      }
                                                  }}];

}
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42