4

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

Yama
  • 2,649
  • 3
  • 31
  • 63
user609906
  • 190
  • 3
  • 6
  • 12

5 Answers5

6

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.

Community
  • 1
  • 1
Kamar Shad
  • 6,089
  • 1
  • 29
  • 56
  • I have done this, and don't see requests coming through to the friend accounts. Is there any requirements other than being friends to see the request? E.g. within my FB app settings, plist etc? – andyc Dec 31 '11 at 09:50
  • 1
    @andyc,Please make sure you have registered you App as "App On Facbook" within your FB app settings.And 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 done things in same way and i am getting the Notification of App request in my Facebook Notifications,I hope you can get The App Request Notification in your Facebook Notification. – Kamar Shad Jan 03 '12 at 12:34
  • how would we do it if we want the user to choose the friends by himself on a dialog? – xus Aug 01 '12 at 15:01
  • @xus we can't choose the friends on dialog ,we need to add friend's facebook id for sending App request,as you can see above – Kamar Shad Aug 02 '12 at 04:46
  • How to set the canvas URL? I cant see it anywhere on the settings page – nr5 Jul 31 '14 at 10:23
1

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.

Andrew Kovzel
  • 601
  • 5
  • 7
  • The first sentence is incorrect. You *can* send an app request without the dialog via POST, assuming the user has the application installed/permissions granted. – typeoneerror Sep 13 '11 at 16:32
0

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);
         }
     }
 }];
Ramdhas
  • 1,765
  • 1
  • 18
  • 26
0

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.

typeoneerror
  • 55,990
  • 32
  • 132
  • 223
0

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

Community
  • 1
  • 1
Kamar Shad
  • 6,089
  • 1
  • 29
  • 56