2014-02-05 52 views
3

我想从我的应用发送好友请求。 我用下面的代码如何通过iOS应用发送好友请求

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"); 
    } 
}]; 

并显示对话框,当我确认它会点击给出消息对不起出事了。我们正在努力尽快解决问题。

我已成功整合了Facebook SDK。我有我的个人资料信息,也是我的朋友列表。所以请帮我解决这个问题。

+0

如果我没有理解https://开头开发商。 facebook.com/docs/reference/dialogs/requests/正确,您必须是本机iOS应用程序(在相应的Facebook应用程序中设置)才能发送此请求 - 您的应用程序设置是否如此? – LordT

+0

另外,你是否检查了当你抛出参数时会发生什么? – LordT

+0

嗨,你没有在这里发送好友请求。你只需在这里分享或发布在朋友墙上。 –

回答

1

替换此

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

编辑:
变化的方法调用

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

,并参考here

+0

嘿,谢谢你的回复,但不工作 – Raj

+0

检查编辑! –

+0

嘿你的代码是在FB墙上发布消息我不想要这个,我想发送朋友的请求给任何其他人在FB上,说我有你的FB ID,然后通过我的应用程序,我可以发送FB朋友请求您。 – Raj

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]; 
     } 
    }}]; 
+0

如果解决您的问题,请接受我的回答请。,, –

+0

嘿谢谢您的回复 – Raj

+0

,但您的代码是FB墙上的帖子消息 我不想要这个,我想发送给其他任何朋友的请求在FB上的人,说我有你的FB ID,然后通过我的应用程序,我可以向你发送FB朋友请求 – Raj

1

检查这个代码。

/* * 事件:完成按钮点击 */

- (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>"]; 
}]; 
} 

/* * 事件:取消按钮点击 */

- (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]; 
                 } 
                }}]; 

} 
相关问题