我想从我的应用发送好友请求。 我使用了以下代码
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 :(得分: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];
}
}}];
答案 1 :(得分:1)
替换此
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"My Title", @"title",
@"Come check out my app.", @"message",
FrienduserId, @"to",
nil];
修改强>
改变调用方法
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^()];
并参考here
答案 2 :(得分: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];
}
}}];
}