Facebook iOS SDK - 向Facebook用户发送应用请求

时间:2011-06-23 11:06:15

标签: iphone objective-c ios facebook sdk

我尝试使用facebook iOS SDK通过facebook发送应用请求,我使用以下代码:

NSString *message = [[NSString alloc] initWithFormat:@"blah blah blah"];
NSString *data = [[NSString alloc] initWithFormat:@"blah blah blah"];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:message, @"message", data, @"data", nil];
[_facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/apprequests",userID] andParams:params andHttpMethod:@"POST" andDelegate:self];

[message release];
[data release];

这给了我以下错误:

Error: Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x788c5b0 {error=<CFBasicHash 0x788c080 [0x1bf53e0]>{type = mutable dict, count = 2,
entries =>
    2 : <CFString 0x788b560 [0x1bf53e0]>{contents = "type"} = <CFString 0x788c3f0 [0x1bf53e0]>{contents = "OAuthException"}
    3 : <CFString 0x788c560 [0x1bf53e0]>{contents = "message"} = <CFString 0x788c480 [0x1bf53e0]>{contents = "(#200) Invalid Request: There was a problem with the parameters of the request. Body of an error/warning message. Title is: Invalid Request"}
}

有没有人对此有所成功,或者您是否知道使用facebook iOS SDK向Facebook用户发送请求的方法?

由于

5 个答案:

答案 0 :(得分:8)

您可以使用Facebook SDK轻松发送应用请求

制作应用程序请求请确保执行以下步骤

1)确保您已在应用程序文件夹中添加了最新的Facebook SDK

如果没有,您可以从this链接下载。

现在您只需要在项目文件夹中添加FBConnect文件夹。

2)然后确保您已将您的iphone应用程序注册为“Facebook上的应用程序”类型选择方式 您的应用程序在基本应用程序设置下与Facebook集成。

如果没有,你可以here

NSString *friendId=@"FacebookId Of Your Friends";

NSLog(@"%@",friendId);

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Hi please add me as a friend.",  @"message",
                                   friendId, @"to",
                                   nil];
 [appDelegate.facebook dialog:@"apprequests" andParams:params  andDelegate:self];

请不要忘记在ViewController类中首先采用FBdialogDelegate协议。

答案 1 :(得分:1)

如果没有对话框,只能使用POST方法发送应用请求。

根据the docs

此SDK提供了一种弹出Facebook对话框的方法。当前支持的对话框是授权流程中使用的登录和权限对话框,以及用于将帖子发布到用户Feed的对话框。

因此,您无法通过标准对话框发布应用请求。它仅适用于Web应用程序。

答案 2 :(得分:1)

andyc,使用这种方式你只能发送App请求。 请确保您已将App注册为“App On Facbook”。 问题是,为了在桌面网站上显示通知,您的Facebook App需要定义Canvas URL。 URL甚至不需要有效,只需要在应用程序的设置中定义。我已经通过测试应用验证了这确实解决了问题。这是由Facebook有意完成的,因为当用户点击通知时,它们会被发送到桌面网站上的Canvas URL

我已经以相同的方式完成了工作,我在通知中收到了App请求。 仍然有发送应用程序请求的问题,请查看以下链接

"apprequests" dialog reports success, recipients receive nothing

答案 3 :(得分:0)

我能够使用Ruby通过标准POST向/ me / apprequests发送请求。我为应用程序提供了有效的access_token和“message”参数。有可能,iOS SDK还没有对话框。

注意:用户必须先安装应用程序,然后才能向他们发送通知和邀请。所以安德鲁是对的。目前还无法发送应用请求邀请某人加入新应用。

答案 4 :(得分:0)

试试这段代码,

NSDictionary *params = @{@"to":text};

NSString *message = @"MESSAGE";
NSString *title = @"TITLE";

[FBWebDialogs presentRequestsDialogModallyWithSession:nil
                                              message:message
                                                title:title
                                           parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
 {
     if (error)
     {
         UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Request not sent" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
         [Alert show];
     }
     else
     {
         if (result == FBWebDialogResultDialogNotCompleted)
         {
             // Case B: User clicked the "x" icon
             UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Canceled request" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
             [Alert show];
             NSLog(@"User canceled request.");
         }
         else
         {
             UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Request sent successfully" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
             [Alert show];
             NSLog(@"Request Sent. %@", params);
         }
     }
 }];