2014-02-05 100 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]; 
                 } 
                }}]; 

} 
相關問題