繁体   English   中英

如何从iOS应用程序发送好友请求

[英]How to send Friend Request From iOS App

我想从我的应用程序发送好友请求。 我使用以下代码

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。 我收到了我的个人资料信息以及我的朋友列表。 所以请帮我解决这个问题。

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

替换这个

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

编辑:
改变调用的方法

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

并参考这里

检查此代码。

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

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM