Facebook iOS SDK - Sending a facebook user an app request

妖精的绣舞 提交于 2019-12-12 07:37:55

问题


Im trying to send an app request through facebook using the facebook iOS SDK, im using the following code:

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?

Thanks


回答1:


You can easily send the app request very easily by Using 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

if not,you may download from this link.

Now you just need to Add FBConnect Folder in your Project Folder.

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.

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.




回答2:


It is not possible to send an app request without the dialog, using just POST method.

According to the docs:

This SDK provides a method for popping up a Facebook dialog. 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.




回答3:


andyc,using that way you can only send the App request. And please make sure you have registered you App as "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. The URL doesn't even need to be valid, it just needs to be defined in the Settings of the App. 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

I have done things in same way and i am getting the App request in my Notifications. still you have problem with sending app request then please view below link

"apprequests" dialog reports success, recipients receive nothing




回答4:


I was able to send a request using Ruby via a standard POST to /me/apprequests. I supplied an valid access_token for the app and the "message" parameter. It's possible, the iOS SDK just doesn't have a dialog for it yet.

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.




回答5:


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


来源:https://stackoverflow.com/questions/6453040/facebook-ios-sdk-sending-a-facebook-user-an-app-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!