【问题标题】:How to send Friend Request From iOS App如何从 iOS 应用发送好友请求
【发布时间】:2014-02-05 11:08:08
【问题描述】:

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

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

【问题讨论】:

标签: ios iphone facebook facebook-graph-api facebook-ios-sdk


【解决方案1】:
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];
         }
     }}];

【讨论】:

  • 如果解决了您的问题,请接受我的回答。,,
  • 但是您的代码是用于在 FB 墙上发布消息的可以向您发送 FB 好友请求。
  • 你没有在这里发送好友请求。你只是在这里分享或发帖在朋友的墙上。
【解决方案2】:

替换这个

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

编辑:
改变调用方法

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

并参考here

【讨论】:

  • 嘿,您的代码用于在 FB 墙上发布消息可以向您发送 FB 好友请求。
  • 你的代码结果说你不能发布到用户墙:(
  • 我认为向任何人发送好友请求是不可能的,除非你有他们的id
【解决方案3】:

检查此代码。

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

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    相关资源
    最近更新 更多