简体   繁体   English

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

[英]Facebook iOS SDK - Sending a facebook user an app request

Im trying to send an app request through facebook using the facebook iOS SDK, im using the following code: 我试图通过Facebook使用facebook iOS SDK发送应用程序请求,我使用以下代码:

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

This gives me the following error: 这给了我以下错误:

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"}
}

So has anyone been successful with this, or do you know of a way to send a request to a facebook user using the facebook iOS SDK? 那么有没有人成功用这个,或者你知道一种使用facebook iOS SDK向facebook用户发送请求的方法吗?

Thanks 谢谢

You can easily send the app request very easily by Using Facebook SDK 您可以使用Facebook SDK轻松发送应用程序请求

For Making App Request Please Make sure Following steps 如需制作应用程序请求请确保执行以下步骤

1)Make sure you have added the latest Facebook SDK in Your Application Folder 1)确保在应用程序文件夹中添加了最新的Facebook SDK

if not,you may download from this link. 如果没有,你可以从下载链接。

Now you just need to Add FBConnect Folder in your Project Folder. 现在,您只需在项目文件夹中添加FBConnect文件夹即可。

2)Then Make sure you have Registered your iphone App as "App on Facebook" Type Select how your app integrates with Facebook under Basic App Settings. 2)然后确保您已将您的iphone应用程序注册为“Facebook上的应用程序”类型在“基本应用程序设置”下选择您的应用程序如何与Facebook集成。

if not,you can do that 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];

Please Don't Forget To Adopt the FBdialogDelegate protocol first in your ViewController Class. 请不要忘记在ViewController类中首先采用FBdialogDelegate协议。

It is not possible to send an app request without the dialog, using just POST method. 仅使用POST方法,无法在没有对话框的情况下发送应用程序请求。

According to the docs : 根据文件

This SDK provides a method for popping up a Facebook dialog. 此SDK提供了弹出Facebook对话框的方法。 The currently supported dialogs are the login and permissions dialogs used in the authorization flow, and a dialog for publishing posts to a user's feed. 当前支持的对话框是授权流程中使用的登录和权限对话框,以及用于将帖子发布到用户的源的对话框。

So you can't post an app request via standard dialogs either. 因此,您也无法通过标准对话框发布应用请求。 It works only for web applications. 它仅适用于Web应用程序。

andyc,using that way you can only send the App request. andyc,使用这种方式你只能发送App请求。 And please make sure you have registered you App as "App On Facbook". 请确保您已将App注册为“App On Facbook”。 The problem is that in order to have the notification displayed on the desktop website, your Facebook App needs to have a Canvas URL defined. 问题是,为了在桌面网站上显示通知,您的Facebook App需要定义Canvas URL。 The URL doesn't even need to be valid, it just needs to be defined in the Settings of the App. URL甚至不需要有效,只需要在应用程序的设置中定义。 I have verified with a test app that this does indeed resolve the problem. 我已经通过测试应用验证了这确实解决了问题。 This is done intentionally by Facebook because when the user clicks on the notification, they are sent to your Canvas URL on the desktop website 这是由Facebook有意完成的,因为当用户点击通知时,它们会被发送到桌面网站上的Canvas URL

I have done things in same way and i am getting the App request in my Notifications. 我以同样的方式做了事情,我在通知中收到了App请求。 still you have problem with sending app request then please view below link 仍然有发送应用程序请求的问题,请查看以下链接

"apprequests" dialog reports success, recipients receive nothing “apprequests”对话框报告成功,收件人什么也得不到

Try this code, 试试这段代码,

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

I was able to send a request using Ruby via a standard POST to /me/apprequests. 我能够通过标准POST向/ me / apprequests使用Ruby发送请求。 I supplied an valid access_token for the app and the "message" parameter. 我为应用程序提供了有效的access_token和“message”参数。 It's possible, the iOS SDK just doesn't have a dialog for it yet. 有可能,iOS SDK还没有对话框。

NOTE: the user has to have installed the application once before you can send them notifications and invites. 注意:用户必须先安装应用程序,然后才能向他们发送通知和邀请。 So Andrew is correct. 所以安德鲁是对的。 There's no way to send an app request to invite someone to join a new app quite yet. 目前还无法发送应用请求邀请某人加入新应用。

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

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